{"id":14287,"date":"2024-04-09T13:44:32","date_gmt":"2024-04-09T05:44:32","guid":{"rendered":"https:\/\/92it.top\/?p=14287"},"modified":"2024-04-09T13:44:34","modified_gmt":"2024-04-09T05:44:34","slug":"stable-diffusion-webui%e5%89%8d%e7%ab%afapi%e5%af%b9%e6%8e%a5","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=14287","title":{"rendered":"Stable Diffusion WebUI\u524d\u7aefAPI\u5bf9\u63a5"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"570\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-25-1024x570.png\" alt=\"\" class=\"wp-image-14288\" style=\"width:446px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-25-1024x570.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-25-300x167.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-25-768x428.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-25-1536x855.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-25-830x462.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-25-230x128.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-25-350x195.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-25-480x267.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-25.png 1958w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>\u80cc\u666f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd AI \u7ed8\u56fe\u5f00\u6e90\u5de5\u5177 Stable Diffusion WebUI \u7684 API \u5f00\u542f\u548c\u57fa\u672c\u8c03\u7528\u65b9\u6cd5\uff0c\u901a\u8fc7\u672c\u6587\u7684\u9605\u8bfb\uff0c\u4f60\u5c06\u4e86\u89e3\u5230 stable-diffusion-webui \u7684\u57fa\u672c\u4ecb\u7ecd\u3001\u5b89\u88c5\u53ca API \u73af\u5883\u914d\u7f6e\uff1b\u6587\u751f\u56fe\u3001\u56fe\u751f\u56fe\u3001\u5c40\u90e8\u91cd\u7ed8\u3001\u540e\u671f\u5904\u7406\u7b49 API \u63a5\u53e3\u8c03\u7528\uff1b\u56fe\u50cf\u5904\u7406\u5f00\u53d1\u4e2d\u5e38\u7528\u5230\u4e00\u4e9b\u65b9\u6cd5\u5982 Base64\u3001PNG\u3001Canvas\u53ca URL \u76f8\u4e92\u8f6c\u6362\u3001Canvas \u989c\u8272\u8f6c\u6362\u7b49\u3002<\/p>\n\n\n\n<p>AI \u7ed8\u56fe\u5de5\u5177\u76ee\u524d\u5e02\u9762\u4e0a\u6bd4\u8f83\u5e7f\u6cdb\u4f7f\u7528\u7684\u4e3b\u8981\u6709\u4e24\u6b3e\uff0c\u4e00\u4e2a\u662f Midjourney\uff0c\u5b83\u63d0\u4f9b\u9762\u5411\u7528\u6237\u6709\u597d\u7684\u64cd\u4f5c\u754c\u9762\uff0c\u6587\u751f\u56fe\u3001\u56fe\u751f\u56fe\u7b49\u529f\u80fd\u975e\u5e38\u5f3a\u5927\uff0c\u4f46\u662f\u5b83\u662f\u4e00\u6b3e\u6536\u8d39\u8f6f\u4ef6\uff1b\u53e6\u4e00\u4e2a\u5c31\u662f\u5f00\u6e90\u5de5\u5177 Stable Diffusion, \u540c\u6837\u5177\u6709\u5f3a\u5927\u7684AI\u7ed8\u56fe\u548c\u56fe\u7247\u518d\u521b\u9020\u80fd\u529b\uff0c\u4f46\u662f\u5b66\u4e60\u6210\u672c\u548c\u4e0a\u624b\u96be\u5ea6\u76f8\u5bf9\u8f83\u5927\uff0c\u4e0d\u8fc7\u7531\u4e8e\u5b83\u662f\u5f00\u6e90\u7684\uff0c\u73b0\u5728\u6709\u975e\u5e38\u591a\u7684\u7528\u6237\u548c\u5f00\u53d1\u8005\uff0c\u6211\u4eec\u53ef\u4ee5\u627e\u5230\u4e30\u5bcc\u7684\u8bad\u7ec3\u6a21\u578b\u548c\u5b66\u4e60\u8d44\u6e90\u3002\u672c\u6587\u4ecb\u7ecd\u7684 Stable Diffusion WebUI \u5c31\u662f\u57fa\u4e8e Stable Diffusion \u7684\u5177\u6709\u6bd4\u8f83\u5b8c\u5584\u7684\u53ef\u89c6\u5316\u64cd\u4f5c\u754c\u9762\u7684 AI \u7ed8\u56fe\u5f00\u6e90\u5de5\u5177\uff0c<\/p>\n\n\n\n<p>\u5b83\u7684\u00a0<code>github<\/code>\u00a0\u8bbf\u95ee\u5730\u5740\u662f\u00a0<a href=\"https:\/\/github.com\/AUTOMATIC1111\/stable-diffusion-webui\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/AUTOMATIC1111\/stable-diffusion-webui<\/a>\u3002<\/p>\n\n\n\n<p><strong>\u73af\u5883\u914d\u7f6e<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<ul>\n<li><strong>\u5b89\u88c5 Stable Diffusion WebUI<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u6211\u4eec\u9996\u5148\u9700\u8981\u5148\u5728\u672c\u5730\u6216\u8005\u670d\u52a1\u5668\u5b89\u88c5\u90e8\u7f72\u00a0<code>Stable Diffusion WebUI<\/code>\uff0c\u53ef\u4ee5\u4ece<a href=\"https:\/\/github.com\/AUTOMATIC1111\/stable-diffusion-webui\" target=\"_blank\" rel=\"noreferrer noopener\">Github<\/a>\u514b\u9686\u4ed3\u5e93\uff0c\u7136\u540e\u6309\u8bf4\u660e\u6587\u6863\u8fdb\u884c\u5b89\u88c5\uff0c\u5bf9\u524d\u7aef\u5f00\u53d1\u6765\u8bf4\u5b89\u88c5\u6d41\u7a0b\u975e\u5e38\u7b80\u5355\uff0c\u8be6\u7ec6\u5b89\u88c5\u6d41\u7a0b\u5927\u5bb6\u53ef\u4ee5\u81ea\u884c\u641c\u7d22\uff0c\u73b0\u5728\u7f51\u4e0a\u5df2\u7ecf\u6709\u5f88\u591a\u4fdd\u59c6\u7ea7\u7684\u6559\u7a0b\uff0c\u672c\u6587\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"538\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-26-1024x538.png\" alt=\"\" class=\"wp-image-14289\" style=\"width:438px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-26-1024x538.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-26-300x158.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-26-768x403.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-26-1536x807.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-26-830x436.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-26-230x121.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-26-350x184.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-26-480x252.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-26.png 1934w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5728\u00a0<code>Windows<\/code>\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u8fdb\u5165\u00a0<code>stable-diffusion-webui<\/code>\u00a0\u6839\u76ee\u5f55\uff0c\u7136\u540e\u53cc\u51fb\u00a0<code>webui-user.bat<\/code>\u00a0\u6587\u4ef6\u5373\u53ef\u5f00\u542f\u672c\u5730\u8fd0\u884c\u670d\u52a1\uff0c\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165\u00a0<code>http:\/\/localhost:7860<\/code>\u00a0\u52a0\u8f7d\u5982\u4e0b\u6240\u793a\u7684\u754c\u9762\u3002\u5728\u00a0<code>txt2img<\/code>\u00a0\u8f93\u5165\u6846\u4e2d\u8f93\u5165\u9700\u8981\u751f\u56fe\u56fe\u50cf\u7684\u7684\u6b63\u5411\u5173\u952e\u8bcd\u548c\u53cd\u5411\u5173\u952e\u8bcd\uff0c\u70b9\u51fb\u00a0<code>Generate<\/code>\u00a0\u6309\u94ae\u5373\u53ef\u751f\u6210\u56fe\u50cf\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"753\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-27-1024x753.png\" alt=\"\" class=\"wp-image-14290\" style=\"width:442px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-27-1024x753.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-27-300x221.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-27-768x565.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-27-1536x1129.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-27-830x610.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-27-230x169.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-27-350x257.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-27-480x353.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-27.png 1956w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u5b8c\u6210\u57fa\u672c\u5b89\u88c5\u540e\uff0c\u8fd8\u53ef\u4ee5\u5b89\u88c5\u754c\u9762\u6c49\u5316\u63d2\u4ef6\u3001\u5173\u952e\u5b57\u4e2d\u6587\u7ffb\u8bd1\u63d2\u4ef6\u3001\u81ea\u5df1\u559c\u6b22\u7684\u98ce\u683c\u6a21\u578b\u7b49\uff0c\u90fd\u53ef\u4ee5\u6309\u7167\u6559\u7a0b\u975e\u5e38\u5bb9\u6613\u5b9e\u73b0\u3002<\/p>\n\n\n\n<ul>\n<li><strong>\u5f00\u542f API \u529f\u80fd<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u5728\u00a0<code>stable-diffusion-webui<\/code>\u00a0\u6839\u76ee\u5f55\u4e0b\u627e\u5230\u6587\u4ef6\u00a0<code>webui-user.bat<\/code>\uff0c\u4f7f\u7528\u7f16\u8f91\u5668\u6253\u5f00\u8fd9\u4e2a\u6587\u4ef6\uff0c\u7136\u540e\u5728\u00a0<code>COMMANDLINE_ARGS<\/code>\u00a0\u914d\u7f6e\u9879\u540e\u9762\u6dfb\u52a0\u00a0<code>--api<\/code>\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">set COMMANDLINE_ARGS= --lowvram --precision full --api --listen<\/pre>\n\n\n\n<p>\u7136\u540e\u53cc\u51fb\u00a0<code>webui-user.bat<\/code>\u00a0\u91cd\u542f\u670d\u52a1\uff0c\u6b64\u65f6\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165\u5730\u5740\u00a0<code>https:\/\/localhost:7860\/doc<\/code>\uff0c\u5c31\u80fd\u770b\u5230\u5982\u4e0b\u6240\u793a\u7684\u6240\u6709\u63a5\u53e3\u6587\u6863\u4e86\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece\u6587\u6863\u4e2d\u627e\u5230\u9700\u8981\u63a5\u5165\u7684\u63a5\u53e3\u53ca\u8be6\u7ec6\u53c2\u6570\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"591\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-28-1024x591.png\" alt=\"\" class=\"wp-image-14291\" style=\"width:482px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-28-1024x591.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-28-300x173.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-28-768x443.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-28-1536x887.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-28-830x479.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-28-230x133.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-28-350x202.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-28-480x277.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-28.png 1926w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>\u5b9e\u73b0<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<ul>\n<li><strong>\u6587\u751f\u56fe<\/strong><\/li>\n<\/ul>\n\n\n\n<p><strong>\u6587\u751f\u56fe\u63a5\u53e3<\/strong>\uff0c\u53ef\u4ee5\u901a\u8fc7\u5411\u00a0<code>stable-diffusion-webui<\/code>\u00a0\u670d\u52a1\u53d1\u9001\u6b63\u5411\u5173\u952e\u5b57\u3001\u53cd\u5411\u5173\u952e\u5b57\u3001\u56fe\u7247\u5c3a\u5bf8\u3001\u91c7\u6837\u6b65\u6570\u7b49\u53c2\u6570\u6765\u8c03\u7528AI\u80fd\u529b\u751f\u6210\u56fe\u7247\u3002\u6211\u4eec\u5148\u6765\u770b\u770b\u5b83\u6709\u54ea\u4e9b\u53ef\u914d\u7f6e\u7684\u00a0<code>payload<\/code>\u00a0\u53c2\u6570\u9009\u9879\u3002\uff08\u6682\u65f6\u53ea\u7528\u5230\u540e\u9762\u5199\u4e86\u6ce8\u91ca\u7684\u53c2\u6570\uff0c\u57fa\u672c\u4e0a\u53ef\u4ee5\u6ee1\u8db3\u5927\u90e8\u5206\u6587\u751f\u56fe\u53c2\u6570\u914d\u7f6e\uff09<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"73\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-29-1024x73.png\" alt=\"\" class=\"wp-image-14292\" style=\"width:726px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-29-1024x73.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-29-300x21.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-29-768x55.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-29-1536x109.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-29-830x59.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-29-230x16.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-29-350x25.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-29-480x34.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-29.png 1658w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"enable_hr\": false,                 \/\/ \u5f00\u542f\u9ad8\u6e05hr\n  \"denoising_strength\": 0,            \/\/ \u964d\u566a\u5f3a\u5ea6\n  \"hr_scale\": 2,                      \/\/ \u9ad8\u6e05\u7ea7\u522b\n  \"hr_upscaler\": \"string\",\n  \"hr_second_pass_steps\": 0,\n  \"hr_resize_x\": 0,\n  \"hr_resize_y\": 0,\n  \"hr_sampler_name\": \"string\",\n  \"hr_prompt\": \"\",\n  \"hr_negative_prompt\": \"\",\n  \"prompt\": \"\",                       \/\/ \u6b63\u5411\u5173\u952e\u5b57\n  \"styles\": [\n    \"string\"\n  ],\n  \"seed\": -1,                         \/\/ \u968f\u673a\u79cd\u5b50\n  \"subseed\": -1,                      \/\/ \u5b50\u7ea7\u79cd\u5b50\n  \"subseed_strength\": 0,              \/\/ \u5b50\u7ea7\u79cd\u5b50\u5f71\u54cd\u529b\u5ea6\n  \"seed_resize_from_h\": -1,\n  \"seed_resize_from_w\": -1,\n  \"sampler_name\": \"string\",\n  \"batch_size\": 1,                    \/\/ \u6bcf\u6b21\u751f\u6210\u7684\u5f20\u6570\n  \"n_iter\": 1,                        \/\/ \u751f\u6210\u6279\u6b21\n  \"steps\": 50,                        \/\/ \u751f\u6210\u6b65\u6570\n  \"cfg_scale\": 7,                     \/\/ \u5173\u952e\u8bcd\u76f8\u5173\u6027\n  \"width\": 512,                       \/\/ \u751f\u6210\u56fe\u50cf\u5bbd\u5ea6\n  \"height\": 512,                      \/\/ \u751f\u6210\u56fe\u50cf\u9ad8\u5ea6\n  \"restore_faces\": false,             \/\/ \u9762\u90e8\u4fee\u590d\n  \"tiling\": false,                    \/\/ \u5e73\u94fa\n  \"do_not_save_samples\": false,\n  \"do_not_save_grid\": false,\n  \"negative_prompt\": \"string\",        \/\/ \u53cd\u5411\u5173\u952e\u5b57\n  \"eta\": 0,                           \/\/ \u7b49\u5f85\u65f6\u95f4\n  \"s_min_uncond\": 0,\n  \"s_churn\": 0,\n  \"s_tmax\": 0,\n  \"s_tmin\": 0,\n  \"s_noise\": 1,\n  \"override_settings\": {},             \/\/ \u8986\u76d6\u6027\u914d\u7f6e\n  \"override_settings_restore_afterwards\": true,\n  \"script_args\": [],                   \/\/ lora \u6a21\u578b\u53c2\u6570\u914d\u7f6e\n  \"sampler_index\": \"Euler\",            \/\/ \u91c7\u6837\u65b9\u6cd5\n  \"script_name\": \"string\",\n  \"send_images\": true,                 \/\/ \u662f\u5426\u53d1\u9001\u56fe\u50cf\n  \"save_images\": false,                \/\/ \u662f\u5426\u5728\u670d\u52a1\u7aef\u4fdd\u5b58\u751f\u6210\u7684\u56fe\u50cf\n  \"alwayson_scripts\": {}               \/\/ alwayson\u914d\u7f6e\n}<\/pre>\n\n\n\n<p>\u6839\u636e\u9700\u8981\u7684\u53c2\u6570\uff0c\u5728\u9875\u9762\u903b\u8f91\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u50cf\u4e0b\u9762\u8fd9\u6837\u5b9e\u73b0\uff0c\u6b64\u65f6\u670d\u52a1\u7aef\u4f1a\u6839\u636e\u63a5\u53e3\u53c2\u6570\uff0c\u4e00\u6b21\u751f\u62104\u5f20\u5bf9\u5e94\u7684\u56fe\u3002\u63a5\u53e3\u8fd4\u56de\u6210\u529f\u4e4b\u540e\uff0c\u6211\u4eec\u4f1a\u63a5\u6536\u5230\u4e00\u4e2a\u5305\u542b\u6240\u6709\u56fe\u7247\u6570\u636e\u540d\u4e3a\u00a0<code>images<\/code>\u00a0\u7684\u6570\u7ec4\uff0c\u6570\u7ec4\u9879\u662f\u683c\u5f0f\u4e3a\u00a0<code>base64<\/code>\u00a0\u7684\u56fe\u7247\uff0c\u6211\u4eec\u53ef\u4ee5\u5411\u4e0b\u9762\u8fd9\u6837\u8f6c\u5316\u4e3a\u9875\u9762\u4e0a\u53ef\u76f4\u63a5\u663e\u793a\u7684\u56fe\u7247\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">const response = await txt2img({\n  id_task: `task(${taskId})`,\n  \/\/ \u6b63\u5411\u5173\u952e\u8bcd\n  prompt: 'xxxx',\n  \/\/ \u53cd\u5411\u5173\u952e\u8bcd\n  negative_prompt: 'xxxx',\n  \/\/ \u968f\u673a\u79cd\u5b50\n  seed: 'xxxx',\n  \/\/ \u751f\u6210\u6b65\u6570\n  steps: 7,\n  \/\/ \u5173\u952e\u8bcd\u76f8\u5173\u6027\n  cfg_scale: 20,\n  width: 1024,\n  height: 1024,\n  \/\/ \u6bcf\u6b21\u751f\u6210\u7684\u5f20\u6570\n  batch_size: 4,\n  \/\/ \u751f\u6210\u6279\u6b21\n  n_iter: 1,\n  \/\/ \u91c7\u6837\u65b9\u6cd5\n  sampler_index: 'xxxx',\n  \/\/ \u91c7\u7528\u7684\u6a21\u578b\u54c8\u5e0c\u503c\n  sd_model_hash: 'xxxx',\n  override_settings: {\n    sd_model_checkpoint: sdModelCheckpoint,\n    eta_noise_seed_delta: 0.0,\n    CLIP_stop_at_last_layers: 1.0,\n  },\n})\nif (response.status === 200 &amp;&amp; response.data) {\n  try {\n    const images = response.data.images;\n    if (images.length === 0) return;\n    data.imageUrls = images.map(item => `data:image\/png;base64,${item}`);\n  } catch (err) {}\n}\n<\/pre>\n\n\n\n<p>\u751f\u6210\u6548\u679c\u5c31\u662f\u672c\u6587\u00a0<code>Banner<\/code>\u00a0\u56fe\u4e2d\u7684\u7c89\u8272\u957f\u5934\u53d1\u7684\u00a0<code>3D<\/code>\u00a0\u5361\u901a\u98ce\u683c\u5c0f\u59d0\u59d0\u00a0<code>\u2728<\/code>\u00a0\uff0c<strong>\u6b63\u5411\u5173\u952e\u5b57<\/strong>\u5927\u81f4\u662f\u00a0<code>girl, long hair, pink<\/code>\uff0c\u6a21\u578b\u91c7\u7528\u7684\u662f\u00a0<code>3dAnimationDiffusion_v10<\/code>\uff0c\u5176\u4ed6\u53c2\u6570\u53ef\u81ea\u884c\u8c03\u8282\u3002\u672c\u6587\u540e\u7eed\u5b9e\u4f8b\u7684<strong>\u56fe\u751f\u56fe<\/strong>\u3001<strong>\u56fe\u4f18\u5316<\/strong>\u90fd\u5c06\u91c7\u7528\u8fd9\u5f20\u56fe\u4f5c\u4e3a<strong>\u53c2\u8003\u56fe<\/strong>\u8fdb\u884c\u6f14\u793a\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"810\" height=\"746\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-30.png\" alt=\"\" class=\"wp-image-14293\" style=\"width:280px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-30.png 810w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-30-300x276.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-30-768x707.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-30-230x212.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-30-350x322.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-30-480x442.png 480w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/figure><\/div>\n\n\n<ul>\n<li><strong>\u56fe\u751f\u56fe<\/strong><\/li>\n<\/ul>\n\n\n\n<p><strong>\u56fe\u751f\u56fe\u63a5\u53e3<\/strong>\uff0c<code>stable-diffusion-webui<\/code>\u00a0\u5c06\u6839\u636e\u6211\u4eec\u4ece\u63a5\u53e3\u4f20\u9001\u7684\u53c2\u8003\u56fe\uff0c\u751f\u6210\u5185\u5bb9\u548c\u98ce\u683c\u7c7b\u4f3c\u7684\u56fe\u7247\uff0c\u5c31\u50cf\u6700\u8fd1\u6296\u97f3\u4e0a\u5f88\u706b\u7684<strong>\u77ac\u606f\u5168\u5b87\u5b99<\/strong>\u7279\u6548\u4e00\u6837\uff0c\u4e5f\u53ef\u4ee5\u5c06\u540c\u4e00\u5f20\u56fe\u7247\u901a\u8fc7\u9009\u62e9\u4e0d\u540c\u6a21\u578b\u8f6c\u5316\u4e3a\u53e6\u4e00\u79cd\u753b\u98ce\u3002\u4e0b\u9762\u662f<strong>\u56fe\u751f\u56fe<\/strong>\u63a5\u53e3\u7684\u8be6\u7ec6\u00a0<code>payload<\/code>\u00a0\u53c2\u6570\uff0c\u53ef\u4ee5\u89c2\u5bdf\u5230\u57fa\u672c\u4e0a\u548c<strong>\u6587\u751f\u56fe<\/strong>\u662f\u4e00\u6837\u7684\uff0c\u591a\u4e86\u4e00\u4e9b\u4e0e<strong>\u53c2\u8003\u56fe\u7247<\/strong>\u76f8\u5173\u7684\u914d\u7f6e\uff0c\u5982\u00a0<code>init_images<\/code>\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"78\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-31-1024x78.png\" alt=\"\" class=\"wp-image-14294\" style=\"width:746px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-31-1024x78.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-31-300x23.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-31-768x58.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-31-830x63.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-31-230x17.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-31-350x27.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-31-480x36.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-31.png 1082w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"init_images\": [\n    \"string\"\n  ],\n  \"resize_mode\": 0,\n  \"denoising_strength\": 0.75,\n  \"image_cfg_scale\": 0,\n  \"mask\": \"string\",\n  \"mask_blur\": 0,\n  \"mask_blur_x\": 4,\n  \"mask_blur_y\": 4,\n  \"inpainting_fill\": 0,\n  \"inpaint_full_res\": true,\n  \"inpaint_full_res_padding\": 0,\n  \"inpainting_mask_invert\": 0,\n  \"initial_noise_multiplier\": 0,\n  \"prompt\": \"\",\n  \"styles\": [\n    \"string\"\n  ],\n  \"seed\": -1,\n  \"subseed\": -1,\n  \"subseed_strength\": 0,\n  \"seed_resize_from_h\": -1,\n  \"seed_resize_from_w\": -1,\n  \"sampler_name\": \"string\",\n  \"batch_size\": 1,\n  \"n_iter\": 1,\n  \"steps\": 50,\n  \"cfg_scale\": 7,\n  \"width\": 512,\n  \"height\": 512,\n  \"restore_faces\": false,\n  \"tiling\": false,\n  \"do_not_save_samples\": false,\n  \"do_not_save_grid\": false,\n  \"negative_prompt\": \"string\",\n  \"eta\": 0,\n  \"s_min_uncond\": 0,\n  \"s_churn\": 0,\n  \"s_tmax\": 0,\n  \"s_tmin\": 0,\n  \"s_noise\": 1,\n  \"override_settings\": {},\n  \"override_settings_restore_afterwards\": true,\n  \"script_args\": [],\n  \"sampler_index\": \"Euler\",\n  \"include_init_images\": false,\n  \"script_name\": \"string\",\n  \"send_images\": true,\n  \"save_images\": false,\n  \"alwayson_scripts\": {}\n}\n<\/pre>\n\n\n\n<p>\u5728\u9875\u9762\u63a5\u53e3\u903b\u8f91\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5176\u4ed6\u53c2\u6570\u548c\u6587\u751f\u56fe\u90fd\u662f\u4e00\u6837\u7684\uff0c\u6211\u4eec\u53ea\u9700\u8981\u628a\u53c2\u8003\u56fe\u4ee5\u00a0<code>base64<\/code>\u00a0\u683c\u5f0f\u6dfb\u52a0\u5230\u00a0<code>init_images<\/code>\u00a0\u6570\u7ec4\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">const response = await img2img({\n  \/\/ \u6b63\u5411\u5173\u952e\u8bcd\n  prompt: prompt,\n  \/\/ \u53cd\u5411\u5173\u952e\u8bcd\n  negative_prompt: negativePrompt,\n  \/\/ \u521d\u59cb\u56fe\u50cf\n  init_images: [sourceImage.value],\n  \/\/ \u5c3a\u5bf8\u7f29\u653e\n  resize_mode: 0,\n  \/\/ ...\n});\n<\/pre>\n\n\n\n<p>\u6211\u4eec\u5c06<strong>\u6587\u751f\u56fe<\/strong>\u793a\u4f8b\u4e2d\u7684\u56fe\u7247\u4f5c\u4e3a<strong>\u53c2\u8003\u56fe<\/strong>\uff0c\u7136\u540e\u5c06\u5927\u6a21\u578b\u5207\u6362\u4e3a\u00a0<code>\u58a8\u5e7d\u4eba\u9020\u4eba_v1030<\/code>\uff0c\u5c31\u80fd\u5f97\u5230\u5982\u4e0b\u56fe\u6240\u793a\u7684<strong>\u771f\u4eba\u5199\u5b9e\u98ce\u683c<\/strong>\u7684\u56fe\u7247\u3002<\/p>\n\n\n\n<ul>\n<li><strong>\u5c40\u90e8\u91cd\u7ed8<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u56fe\u751f\u56fe&nbsp;<code>API<\/code>&nbsp;\u8fd8\u53ef\u4ee5\u5b9e\u73b0\u56fe\u7247<strong>\u5c40\u90e8\u91cd\u7ed8\u3001\u6d82\u9e26\u3001\u91cd\u7ed8\u8499\u7248\u3001\u9ad8\u6e05\u653e\u5927\u3001\u56fe\u50cf\u6269\u5145<\/strong>\u7b49\u6548\u679c\u3002\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u7b80\u5355\u8bb2\u89e3\u4ee5\u4e0b\u5982\u4f55\u5b9e\u73b0\u5c40\u90e8\u91cd\u7ed8\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u8981\u5b9e\u73b0<strong>\u5c40\u90e8\u91cd\u7ed8<\/strong>\u529f\u80fd\uff0c\u9996\u5148\u6211\u4eec\u9700\u8981\u4f7f\u7528&nbsp;<code>Canvas<\/code>&nbsp;\u521b\u5efa\u4e00\u4e2a\u753b\u5e03\uff0c<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"475\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-32-1024x475.png\" alt=\"\" class=\"wp-image-14296\" style=\"width:502px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-32-1024x475.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-32-300x139.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-32-768x356.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-32-830x385.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-32-230x107.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-32-350x162.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-32-480x222.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-32.png 1316w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u7136\u540e\u901a\u8fc7\u9f20\u6807\u79fb\u52a8\u5728\u753b\u5e03\u4e0a<strong>\u6d82\u62b9<\/strong>\u51fa\u9700\u8981\u91cd\u7ed8\u7684\u8def\u5f84\uff0c\u5728\u5b9e\u9645\u5f00\u53d1\u65f6\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2a\u5982\u4e0b\u56fe\u6240\u793a\u7684\u56fe\u7247\u91cd\u7ed8\u7f16\u8f91\u5668\uff0c\u53f3\u4fa7\u56fe\u7247\u9ec4\u8272\u533a\u57df\u00a0<code>\ud83d\udfe8<\/code>\u00a0\u662f\u7ecf\u8fc7\u753b\u7b14\u6d82\u62b9\u9700\u8981\u91cd\u7ed8\u4fee\u6539\u7684\u533a\u57df\u3002\u6d82\u62b9\u529f\u80fd\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u7b80\u5355\u5b9e\u73b0\uff0c\u50cf<strong>\u64e6\u9664<\/strong>\u3001<strong>\u753b\u7b14\u5927\u5c0f\u989c\u8272\u9009\u62e9<\/strong>\u3001<strong>\u64a4\u9500\u91cd\u505a<\/strong>\u7b49\u6269\u5c55\u529f\u80fd\u53ef\u81ea\u884c\u641c\u7d22\u5982\u4f55\u5b9e\u73b0\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"483\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-33-1024x483.png\" alt=\"\" class=\"wp-image-14297\" style=\"width:516px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-33-1024x483.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-33-300x142.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-33-768x362.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-33-830x392.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-33-230x109.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-33-350x165.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-33-480x226.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-33.png 1314w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;div>\n  &lt;canvas id=\"canvas\">&lt;\/canvas>\n  &lt;img src=\"your_image.jpg\" id=\"image\">\n  &lt;button onclick=\"clearMask()\">\u6e05\u9664\u906e\u7f69&lt;\/button>\n&lt;\/div>\n\n&lt;script>\nvar canvas = document.getElementById('canvas');\nvar image = document.getElementById('image');\n\/\/ \u8bbe\u7f6ecanvas\u5bbd\u9ad8\u4e0e\u56fe\u50cf\u5c3a\u5bf8\u76f8\u540c\ncanvas.width = image.width;\ncanvas.height = image.height;\nvar ctx = canvas.getContext('2d');\nvar isDrawing = false; \/\/ \u662f\u5426\u6b63\u5728\u7ed8\u5236\nvar lastX = 0;\nvar lastY = 0;\n\/\/ \u9f20\u6807\u6309\u4e0b\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\ncanvas.addEventListener('mousedown', function(e) {\n  isDrawing = true;\n  [lastX, lastY] = [e.offsetX, e.offsetY];\n});\n\/\/ \u9f20\u6807\u79fb\u52a8\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\ncanvas.addEventListener('mousemove', function(e) {\n  if (!isDrawing) return;\n  drawMask(e.offsetX, e.offsetY);\n});\n\/\/ \u9f20\u6807\u91ca\u653e\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\ncanvas.addEventListener('mouseup', function() {\n  isDrawing = false;\n});\n\/\/ \u7ed8\u5236\u906e\u7f69\u51fd\u6570\nfunction drawMask(x, y) {\n  ctx.beginPath();\n  ctx.moveTo(lastX, lastY);\n  ctx.lineTo(x, y);\n  ctx.strokeStyle = 'rgba(0, 0, 0, 1)'; \/\/ \u8bbe\u7f6e\u906e\u7f69\u989c\u8272\uff08\u9ed1\u8272\uff09\n  ctx.lineWidth = 20;                   \/\/ \u8bbe\u7f6e\u906e\u7f69\u5bbd\u5ea6\n  ctx.lineCap = 'round';                \/\/ \u8bbe\u7f6e\u7ebf\u6761\u672b\u7aef\u5f62\u72b6\u4e3a\u5706\u5f62\n  ctx.stroke();\n  [lastX, lastY] = [x, y];\n}\n\/\/ \u6e05\u9664\u906e\u7f69\u51fd\u6570\nfunction clearMask() {\n  ctx.clearRect(0, 0, canvas.width, canvas.height);\n}\n&lt;\/script>\n<\/pre>\n\n\n\n<p>\u6d82\u62b9\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u53f3\u952e\u4fdd\u5b58\u56fe\u7247\uff0c\u53ef\u4ee5\u5f97\u5230\u5982\u4e0b\u56fe\u5de6\u4fa7\u6240\u793a\u7684\u56fe\u7247\u3002\u4f46\u662f\u00a0<code>stable-diffusion-webui<\/code>\u00a0\u9700\u8981\u7684\u00a0<strong>Mask\u906e\u7f69\u56fe\u662f\u6d82\u6539\u533a\u57df\u4e3a\u7eaf\u767d\u8272\uff0c\u975e\u4fee\u6539\u533a\u57df\u4e3a\u9ed1\u8272\uff0c\u4e14\u5927\u5c0f\u9700\u8981\u548c\u539f\u56fe\u4e00\u81f4<\/strong>\uff0c\u5982\u53f3\u4fa7\u56fe\u7247\u6240\u793a\u3002\u6b64\u65f6\u5c31\u9700\u8981\u5c06\u5f97\u5230\u7684\u5de6\u4fa7\u900f\u660e\u906e\u7f69\u5c42\u8f6c\u6362\u4e3a\u53f3\u4fa7\u9700\u8981\u7684\u906e\u7f69\u5c42\u56fe\u7247\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"606\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-34-1024x606.png\" alt=\"\" class=\"wp-image-14298\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-34-1024x606.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-34-300x178.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-34-768x455.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-34-830x491.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-34-230x136.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-34-350x207.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-34-480x284.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-34.png 1314w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><code>Canvas<\/code>\u00a0\u906e\u7f69\u5c42\u8f6c\u6362\u65b9\u6cd5\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u5b9e\u73b0\uff0c\u7ed8\u5236\u00a0<code>Mask<\/code>\u00a0\u56fe\u7247\uff0c<code>Canvas<\/code>\u00a0\u4f7f\u7528\u9f20\u6807\u7ed8\u5236\u9ed1\u8272\u56fe\u6848\uff0c\u5bfc\u51fa\u56fe\u7247\u65f6\u9700\u8981\u628a\u7a7a\u767d\u90e8\u5206\u53d8\u4e3a\u9ed1\u8272\uff0c\u7ed8\u5236\u7ebf\u6761\u7684\u90e8\u5206\u53d8\u4e3a\u767d\u8272\uff0c\u5e76\u4e14\u9700\u8981\u8f6c\u6362\u6210\u548c\u539f\u56fe\u76f8\u540c\u7684\u5c3a\u5bf8\u3002\u5176\u4e2d\u4e24\u4e2a\u53c2\u6570\u00a0<code>_canvas<\/code>\u00a0\u662f\u9700\u8981\u8f6c\u6362\u7684\u753b\u5e03\uff0c<code>_image<\/code>\u00a0\u662f\u6d82\u62b9\u7684\u539f\u56fe\u3002\u5176\u4e2d\u7528\u4e8e\u83b7\u53d6\u56fe\u50cf\u539f\u59cb\u5c3a\u5bf8\u7684\u65b9\u6cd5\u00a0<code>getImageOriginSize<\/code>\u00a0\u53ef\u4ee5\u5728\u672c\u6587\u672b\u5c3e\u65b9\u6cd5\u6c47\u603b\u4e2d\u67e5\u770b<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export const drawMask = async (_canvas, _image) => {\n  return new Promise(async(resolve) => {\n    const canvas = _canvas;\n    const ctx = canvas.getContext('2d');\n    const imageData = ctx.getImageData(0, 0, canvas.clientWidth, canvas.clientHeight);\n    const imageDataContent = imageData.data;\n    \/\/ \u4fee\u6539\u56fe\u50cf\u6570\u636e\u4e2d\u7684\u50cf\u7d20\u989c\u8272\n    for (let i = 0; i &lt; imageDataContent.length; i += 4) {\n      \/\/ \u5224\u65ad\u900f\u660e\u5ea6\u662f\u5426\u5c0f\u4e8e\u9608\u503c\n      if (imageDataContent[i + 3] &lt; 128) {\n      \/\/ \u5c06\u900f\u660e\u90e8\u5206\u8bbe\u7f6e\u4e3a\u9ed1\u8272\n        imageDataContent[i] = 0;\n        imageDataContent[i + 1] = 0;\n        imageDataContent[i + 2] = 0;\n        imageDataContent[i + 3] = 255;\n      } else {\n        \/\/ \u5c06\u7ebf\u6761\u90e8\u5206\u8bbe\u7f6e\u4e3a\u767d\u8272\n        imageDataContent[i] = 255;\n        imageDataContent[i + 1] = 255;\n        imageDataContent[i + 2] = 255;\n        imageDataContent[i + 3] = 255;\n      }\n    }\n    \/\/ \u5c06\u4fee\u6539\u540e\u7684\u56fe\u50cf\u6570\u636e\u5bfc\u51fa\u4e3a\u56fe\u7247\u683c\u5f0f\n    const exportCanvas = document.createElement('canvas');\n    exportCanvas.width = canvas.clientWidth;\n    exportCanvas.height = canvas.clientHeight;\n    const exportCtx = exportCanvas.getContext('2d');\n    exportCtx.putImageData(imageData, 0, 0);\n    \/\/ mask\u653e\u5927\u5230\u548c\u539f\u56fe\u4e00\u81f4\n    const size = await getImageOriginSize(_image);\n    const finalMask = await scaleImage(exportCanvas.toDataURL(), size.width, size.height);\n    resolve(finalMask);\n  });\n}<\/pre>\n\n\n\n<p>\u7136\u540e\u6211\u4eec\u5c06\u8f6c\u6362\u540e\u7684\u906e\u7f69\u56fe\u4ee5\u00a0<code>base64<\/code>\u00a0\u7684\u5f62\u5f0f\u4f5c\u4e3a\u00a0<code>mask<\/code>\u00a0\u53c2\u6570\u6dfb\u52a0\u5230\u63a5\u53e3\u53c2\u6570\u4e2d\uff0c\u6dfb\u52a0\u4e00\u4e9b\u6b63\u5411\u5173\u952e\u5b57\u7b49\u53c2\u6570\u8fdb\u884c\u56fe\u751f\u56fe\u63a5\u53e3\u8bf7\u6c42\uff0c\u8fd4\u56de\u7ed3\u679c\u548c\u4e0a\u8ff0\u00a0<code>API<\/code>\u00a0\u90fd\u662f\u4e00\u6837\u7684\uff0c\u6700\u7ec8\u5c31\u53ef\u4ee5\u5f97\u5230\u4e0b\u9762\u6240\u793a\u7684\u56fe\u50cf\uff0c\u53ef\u4ee5\u89c2\u5bdf\u5230\u88ab\u6d82\u62b9\u533a\u57df\u7684\u82b1\u6735\u6d88\u5931\u4e86\u00a0<code>\ud83c\udf3a<\/code>\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">const response = await img2img({\n  init_images: [sourceImage.value],\n  mask: data.mask,\n  \/\/ ...\n});\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"472\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-35-1024x472.png\" alt=\"\" class=\"wp-image-14299\" style=\"width:432px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-35-1024x472.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-35-300x138.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-35-768x354.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-35-830x383.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-35-230x106.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-35-350x161.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-35-480x221.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-35.png 1322w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<ul>\n<li><strong>\u540e\u671f\u5904\u7406<\/strong><\/li>\n<\/ul>\n\n\n\n<p><strong>\u540e\u671f\u5904\u7406\u63a5\u53e3<\/strong>\uff0c\u53ef\u4ee5\u5b9e\u73b0\u56fe\u7247<strong>\u9ad8\u6e05\u653e\u5927\u3001\u88c1\u5207\u3001\u6269\u5145<\/strong>\u7b49\u529f\u80fd\uff0c\u6709\u6279\u91cf\u548c\u5355\u56fe\u8c03\u6574\u4e24\u79cd\u63a5\u53e3\uff0c\u5982\u4e0b\u6240\u793a\u662f\u5355\u56fe\u8c03\u6574\u63a5\u53e3\u3002\u6211\u4eec\u5148\u6765\u770b\u770b\u5355\u56fe\u4f18\u5316\u00a0<code>API<\/code>\u00a0\u53ef\u4ee5\u63a5\u6536\u7684\u53c2\u6570\u6709\u54ea\u4e9b\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"79\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-36-1024x79.png\" alt=\"\" class=\"wp-image-14300\" style=\"width:726px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-36-1024x79.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-36-300x23.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-36-768x60.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-36-830x64.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-36-230x18.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-36-350x27.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-36-480x37.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-36.png 1108w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"resize_mode\": 0,\n  \"show_extras_results\": true,\n  \"gfpgan_visibility\": 0,\n  \"codeformer_visibility\": 0,\n  \"codeformer_weight\": 0,\n  \"upscaling_resize\": 2,\n  \"upscaling_resize_w\": 512,\n  \"upscaling_resize_h\": 512,\n  \"upscaling_crop\": true,\n  \"upscaler_1\": \"None\",\n  \"upscaler_2\": \"None\",\n  \"extras_upscaler_2_visibility\": 0,\n  \"upscale_first\": false,\n  \"image\": \"\"                       \/\/ \u539f\u56fe\n}\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"494\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-37-1024x494.png\" alt=\"\" class=\"wp-image-14301\" style=\"width:508px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-37-1024x494.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-37-300x145.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-37-768x371.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-37-830x400.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-37-230x111.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-37-350x169.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-37-480x232.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-37.png 1314w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><code>stable-diffusion-webui<\/code>\u00a0\u8fd8\u6709\u8bb8\u591a\u5b9e\u7528\u7684\u00a0<code>API<\/code>\u00a0\u53ef\u4ee5\u8c03\u7528\uff0c\u6bd4\u5982\u53ef\u4ee5\u901a\u8fc7<strong>\u8fdb\u5ea6\u67e5\u8be2<\/strong>\u63a5\u53e3\u5b9e\u65f6\u83b7\u53d6\u5230\u751f\u6210\u56fe\u7247\u7684\u8fdb\u5ea6\u3001\u5269\u4f59\u65f6\u95f4\u3001\u6392\u961f\u72b6\u6001\u7b49\u3001\u53ef\u4ee5\u901a\u8fc7<strong>\u914d\u7f6e\u67e5\u8be2<\/strong>\u63a5\u53e3\u83b7\u53d6\u5230\u914d\u7f6e\u4fe1\u606f\u3001\u5df2\u5b89\u88c5\u7684\u6a21\u578b\u5217\u8868\u7b49\uff1b<strong>\u53cd\u5411\u63a8\u7406<\/strong>\u63a5\u53e3\u53ef\u4ee5\u901a\u8fc7\u5df2\u751f\u6210\u7684\u56fe\u7247\u53cd\u63a8\u51fa\u56fe\u50cf\u4fe1\u606f\u3001\u63cf\u8ff0\u5173\u952e\u5b57\u7b49\u3002\u5177\u4f53\u63a5\u53e3\u4f7f\u7528\u65b9\u6cd5\u548c\u53c2\u6570\u90fd\u53ef\u4ee5\u5728\u00a0<code>API<\/code>\u00a0\u6587\u6863\u4e2d\u67e5\u8be2\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"76\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-38-1024x76.png\" alt=\"\" class=\"wp-image-14302\" style=\"width:666px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-38-1024x76.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-38-300x22.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-38-768x57.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-38-830x62.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-38-230x17.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-38-350x26.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-38-480x36.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/04\/image-38.png 1104w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<ul>\n<li><strong>\u5b9e\u7528\u65b9\u6cd5<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u5728\u505a\u00a0<code>Web<\/code>\u00a0\u56fe\u7247\u5904\u7406\u5e94\u7528\u65f6\u9700\u8981\u7528\u5230\u5f88\u591a\u56fe\u7247\u76f8\u5173\u7684\u5b9e\u7528\u65b9\u6cd5\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u7b80\u5355\u6c47\u603b\u3002<\/p>\n\n\n\n<p>\u2460 Canvas\u8f6cBase64\/PNG<\/p>\n\n\n\n<p>\u8981\u5c06\u00a0<code>Canvas<\/code>\u00a0\u8f6c\u6362\u4e3a\u00a0<code>Base64<\/code>\u00a0\u683c\u5f0f\u56fe\u50cf\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u00a0<code>Canvas<\/code>\u00a0\u7684\u00a0<code>toDataURL()<\/code>\u00a0\u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u5c06\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u56fe\u50cf\u6570\u636e\u7684\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u5305\u62ec\u56fe\u50cf\u7684\u7c7b\u578b\uff0c\u5982\u00a0<code>image\/png<\/code>\u00a0\u548c\u00a0<code>Base64<\/code>\u00a0\u7f16\u7801\u7684\u56fe\u50cf\u6570\u636e\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u83b7\u53d6 Canvas \u5143\u7d20\nvar canvas = document.getElementById(\"myCanvas\");\nvar ctx = canvas.getContext(\"2d\");\n\/\/ \u5c06 Canvas \u8f6c\u6362\u4e3a Base64 \u683c\u5f0f\u7684\u56fe\u50cf\u6570\u636e\nvar dataURL = canvas.toDataURL();<\/pre>\n\n\n\n<p>\u2461 \u56fe\u7247URL\u8f6cBase64<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export const convertUrlToBase64 = src => {\n  return new Promise(resolve => {\n    const img = new Image()\n    img.crossOrigin = ''\n    img.src = src\n    img.onload = function () {\n      const canvas = document.createElement('canvas');\n      canvas.width = img.width;\n      canvas.height = img.height;\n      const ctx = canvas.getContext('2d');\n      ctx.drawImage(img, 0, 0, img.width, img.height);\n      const ext = img.src.substring(img.src.lastIndexOf('.') + 1).toLowerCase();\n      const dataURL = canvas.toDataURL('image\/' + ext);\n      resolve(dataURL);\n    }\n  });\n};<\/pre>\n\n\n\n<p>\u2462 Base64\u8f6cPNG<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export const convertBase64ToImage = src => {\n  return new Promise((resolve) => {\n    const arr = src.split(',');\n    const byteString = atob(arr[1]);\n    const ab = new ArrayBuffer(byteString.length);\n    const ia = new Uint8Array(ab);\n    for (let i = 0; i &lt; byteString.length; i++) {\n      ia[i] = byteString.charCodeAt(i);\n    }\n    const file = new File([ab], generateRandomId(), { type: 'image\/png' });\n    resolve(file);\n  });\n}<\/pre>\n\n\n\n<p>\u2463 \u83b7\u53d6\u56fe\u50cf\u539f\u59cb\u5c3a\u5bf8<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export const getImageOriginSize = (src) => {\n  return new Promise((resolve) => {\n    const image = new Image();\n    image.src = src;\n    image.onload = () => {\n      resolve({\n        width: image.naturalWidth,\n        height: image.naturalHeight\n      });\n    };\n  });\n}\n<\/pre>\n\n\n\n<p>\u2464 \u7b49\u6bd4\u7f29\u653eBase64<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export const scaleImage = (src, width, height) => {\n  return new Promise((resolve) => {\n    const image = new Image();\n    image.src = src;\n    image.onload = () => {\n      const canvas = document.createElement('canvas');\n      canvas.width = width;\n      canvas.height = height;\n      const ctx = canvas.getContext('2d');\n      ctx.drawImage(image, 0, 0, width, height);\n      resolve(canvas.toDataURL());\n    };\n  })\n};<\/pre>\n\n\n\n<p>\u8fd8\u6709\u4e0a\u8ff0\u6587\u7ae0\u4e2d\u63d0\u5230\u7684\u5c06\u900f\u660e\u5f69\u8272\u00a0<code>Canvas<\/code>\u00a0\u8f6c\u5316\u4e3a\u00a0<code>stable-diffusion-webui<\/code>\u00a0\u5c40\u90e8\u91cd\u7ed8\u6240\u9700\u7684<strong>\u9ed1\u5e95\u767d\u8272\u56fe\u6848<\/strong>\u65b9\u6cd5\u7b49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f \u672c\u6587\u4e3b\u8981\u4ecb\u7ecd AI \u7ed8\u56fe\u5f00\u6e90\u5de5\u5177 Stable Diffusion WebUI \u7684 API \u5f00\u542f\u548c\u57fa\u672c\u8c03 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/14287"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14287"}],"version-history":[{"count":3,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/14287\/revisions"}],"predecessor-version":[{"id":14304,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/14287\/revisions\/14304"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}