返回列表 发布新帖

gpt-image2生图网站源码

4009 1
dhgj686 发表于 2026-4-26 00:00:17 | 查看全部 阅读模式 <

马上注册,结交更多好友,享用更多功能,让你轻松玩转小K网。

您需要 登录 才可以下载或查看,没有账号?立即注册 微信登录

×
宠粉福利🔥 gpt-image2生图网站源码,正式公开啦!
gpt-image2生图网站源码

之前很多小伙伴问我,能不能分享gpt-image2的生图源码,今天它来啦✨ 不管你是编程爱好者、开发者,还是想搭建自己的生图网站,这份源码直接安排,零保留分享!
✅ 源码完整可直接部署:无需二次开发,下载后按照教程操作,就能快速搭建属于自己的AI生图网站,省去从零开发的麻烦,小白开发者也能轻松上手
✅ 核心功能无删减:保留原网站全部核心能力——零门槛文字生图、高清无水印输出、多风格适配、快速出图,所有功能均可正常使用、自由修改
✅ 开源可定制:源码完全开源,支持自由修改功能、调整界面风格、添加专属模块,满足不同开发者的个性化需求,商用、自用都可(合规范围内);补充说明:源码接口调用的是第三方API,单次调用成本约0.04,成本透明,可根据自身需求调整调用频次;大家只需从指定链接注册,获取APIKey后放到网站对应配置处,即可直接使用,操作简单无门槛
✅ 附带详细部署教程:担心不会操作?配套完整图文教程,从下载、配置到部署,一步一步讲解,全程无难点,跟着做就能成功搭建
不管你是想练手编程、搭建个人项目,还是想批量部署生图网站,这份gpt-image2源码都能帮你少走弯路,省去大量开发时间!
无需转发、无需集赞,直接获取源码👇
【api接口地址】:接口地址
温馨提示:源码可自由修改,但禁止用于违规用途哦~ 拿到源码的小伙伴,欢迎评论区反馈部署效果,互相交流学习!🎉
#gptimage2源码 #AI生图源码 #开源源码 #编程福利 #开发者必备 #生图网站搭建 #源码分享
源码
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4.     <meta charset="UTF-8" />
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6.     <title>多米AI · 图像工坊</title>
  7.     <script src="https://cdn.tailwindcss.com">
  8.     </script>
  9.     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" />
  10.     <style>
  11.         @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Noto+Sans+SC:wght@300;400;500;600;700&display=swap');
  12.         * {
  13.             margin: 0;
  14.             padding: 0;
  15.             box-sizing: border-box;
  16.         }
  17.         body {
  18.             font-family: 'Inter', 'Noto Sans SC', system-ui, sans-serif;
  19.             background: #f5f7fb;
  20.             color: #1e1e2f;
  21.             min-height: 100vh;
  22.             -webkit-font-smoothing: antialiased;
  23.         }
  24.         /* ===== 滚动条 ===== */
  25.         ::-webkit-scrollbar {
  26.             width: 4px;
  27.             height: 4px;
  28.         }
  29.         ::-webkit-scrollbar-track {
  30.             background: transparent;
  31.         }
  32.         ::-webkit-scrollbar-thumb {
  33.             background: rgba(99, 102, 241, .2);
  34.             border-radius: 20px;
  35.         }
  36.         ::-webkit-scrollbar-thumb:hover {
  37.             background: rgba(99, 102, 241, .4);
  38.         }
  39.         /* ===== 顶部导航 ===== */
  40.         .navbar-light {
  41.             background: rgba(255, 255, 255, 0.85);
  42.             backdrop-filter: blur(18px) saturate(1.6);
  43.             border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  44.         }
  45.         /* ===== 卡片通用 ===== */
  46.         .card-light {
  47.             background: #ffffff;
  48.             border: 1px solid rgba(0, 0, 0, 0.06);
  49.             border-radius: 24px;
  50.             transition: border-color 0.25s, box-shadow 0.3s;
  51.         }
  52.         .card-light:hover {
  53.             border-color: rgba(99, 102, 241, 0.15);
  54.             box-shadow: 0 12px 40px -12px rgba(0, 0, 0, 0.06);
  55.         }
  56.         /* ===== 输入框 ===== */
  57.         .input-light {
  58.             background: #ffffff;
  59.             border: 1px solid #e2e4ea;
  60.             border-radius: 14px;
  61.             padding: 12px 18px;
  62.             color: #1e1e2f;
  63.             font-size: 0.9rem;
  64.             transition: all 0.25s;
  65.             outline: none;
  66.             width: 100%;
  67.         }
  68.         .input-light:focus {
  69.             border-color: #818cf8;
  70.             box-shadow: 0 0 0 4px rgba(129, 140, 248, 0.10);
  71.         }
  72.         .input-light::placeholder {
  73.             color: #a0a3b1;
  74.             font-weight: 300;
  75.         }
  76.         /* ===== 文本域 ===== */
  77.         .textarea-light {
  78.             background: #ffffff;
  79.             border: 1px solid #e2e4ea;
  80.             border-radius: 18px;
  81.             padding: 18px 22px;
  82.             color: #1e1e2f;
  83.             font-size: 0.95rem;
  84.             line-height: 1.7;
  85.             transition: all 0.25s;
  86.             outline: none;
  87.             resize: vertical;
  88.             min-height: 100px;
  89.             width: 100%;
  90.             font-family: inherit;
  91.         }
  92.         .textarea-light:focus {
  93.             border-color: #818cf8;
  94.             box-shadow: 0 0 0 4px rgba(129, 140, 248, 0.08);
  95.         }
  96.         .textarea-light::placeholder {
  97.             color: #a0a3b1;
  98.             font-weight: 300;
  99.         }
  100.         /* ===== 按钮主色 ===== */
  101.         .btn-primary {
  102.             background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  103.             border: none;
  104.             border-radius: 18px;
  105.             padding: 16px 32px;
  106.             font-weight: 600;
  107.             font-size: 1.05rem;
  108.             color: #ffffff;
  109.             cursor: pointer;
  110.             transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  111.             box-shadow: 0 8px 28px -8px rgba(99, 102, 241, 0.35);
  112.             display: inline-flex;
  113.             align-items: center;
  114.             justify-content: center;
  115.             gap: 10px;
  116.             width: 100%;
  117.             letter-spacing: 0.2px;
  118.         }
  119.         .btn-primary:hover {
  120.             transform: scale(1.008);
  121.             box-shadow: 0 12px 40px -8px rgba(99, 102, 241, 0.45);
  122.             filter: brightness(1.04);
  123.         }
  124.         .btn-primary:active {
  125.             transform: scale(0.98);
  126.         }
  127.         .btn-primary:disabled {
  128.             opacity: 0.5;
  129.             cursor: not-allowed;
  130.             transform: none;
  131.             filter: none;
  132.             box-shadow: none;
  133.         }
  134.         /* ===== 比例按钮 ===== */
  135.         .ratio-btn {
  136.             background: #ffffff;
  137.             border: 1px solid #e2e4ea;
  138.             border-radius: 14px;
  139.             padding: 10px 8px;
  140.             text-align: center;
  141.             cursor: pointer;
  142.             transition: all 0.25s;
  143.             user-select: none;
  144.         }
  145.         .ratio-btn:hover {
  146.             border-color: #a5b4fc;
  147.             background: #f8f9ff;
  148.         }
  149.         .ratio-btn.active {
  150.             background: #6366f1;
  151.             border-color: #6366f1;
  152.             color: #ffffff;
  153.             box-shadow: 0 4px 12px rgba(99, 102, 241, 0.20);
  154.         }
  155.         .ratio-btn.active .desc {
  156.             color: rgba(255, 255, 255, 0.7);
  157.         }
  158.         .ratio-btn .label {
  159.             font-size: 1rem;
  160.             font-weight: 700;
  161.             font-family: 'Inter', monospace;
  162.             letter-spacing: 0.3px;
  163.         }
  164.         .ratio-btn .desc {
  165.             font-size: 0.65rem;
  166.             color: #9ca3af;
  167.             margin-top: 1px;
  168.         }
  169.         .ratio-btn.active .desc {
  170.             color: rgba(255, 255, 255, 0.7);
  171.         }
  172.         /* ===== 灵感标签 ===== */
  173.         .prompt-tag {
  174.             background: #f8f9ff;
  175.             border: 1px solid #e8eaf0;
  176.             border-radius: 100px;
  177.             padding: 8px 16px;
  178.             font-size: 0.8rem;
  179.             color: #4b4d5c;
  180.             cursor: pointer;
  181.             transition: all 0.25s;
  182.             user-select: none;
  183.             display: inline-block;
  184.             line-height: 1.4;
  185.         }
  186.         .prompt-tag:hover {
  187.             background: #eef0ff;
  188.             border-color: #a5b4fc;
  189.             color: #4338ca;
  190.             transform: translateY(-1px);
  191.         }
  192.         /* ===== 历史卡片 ===== */
  193.         .history-card {
  194.             border-radius: 14px;
  195.             overflow: hidden;
  196.             background: #ffffff;
  197.             border: 1px solid #f0f1f5;
  198.             transition: all 0.3s;
  199.             cursor: pointer;
  200.         }
  201.         .history-card:hover {
  202.             border-color: #d0d5f0;
  203.             box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
  204.             transform: translateY(-2px);
  205.         }
  206.         .history-card img {
  207.             width: 100%;
  208.             aspect-ratio: 16/9;
  209.             object-fit: cover;
  210.             display: block;
  211.             background: #f5f6fa;
  212.         }
  213.         .history-card .info {
  214.             padding: 10px 12px 12px;
  215.         }
  216.         .history-card .info p {
  217.             font-size: 0.75rem;
  218.             color: #6b7280;
  219.             display: -webkit-box;
  220.             -webkit-line-clamp: 2;
  221.             -webkit-box-orient: vertical;
  222.             overflow: hidden;
  223.             line-height: 1.5;
  224.         }
  225.         /* ===== 结果卡片 ===== */
  226.         .result-card {
  227.             border-radius: 18px;
  228.             overflow: hidden;
  229.             background: #ffffff;
  230.             border: 1px solid #f0f1f5;
  231.             transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  232.             cursor: pointer;
  233.         }
  234.         .result-card:hover {
  235.             transform: translateY(-4px) scale(1.01);
  236.             border-color: #c7d2fe;
  237.             box-shadow: 0 16px 48px -12px rgba(99, 102, 241, 0.10);
  238.         }
  239.         .result-card img {
  240.             width: 100%;
  241.             aspect-ratio: 16/9;
  242.             object-fit: cover;
  243.             display: block;
  244.             background: #f5f6fa;
  245.         }
  246.         .result-card .actions {
  247.             padding: 12px 14px 14px;
  248.             display: flex;
  249.             gap: 8px;
  250.         }
  251.         .result-card .actions button {
  252.             flex: 1;
  253.             padding: 8px 0;
  254.             border-radius: 12px;
  255.             border: none;
  256.             background: #f5f6fa;
  257.             color: #4b4d5c;
  258.             font-size: 0.75rem;
  259.             font-weight: 500;
  260.             cursor: pointer;
  261.             transition: all 0.2s;
  262.             display: flex;
  263.             align-items: center;
  264.             justify-content: center;
  265.             gap: 6px;
  266.         }
  267.         .result-card .actions button:hover {
  268.             background: #eef0ff;
  269.             color: #4338ca;
  270.         }
  271.         /* ===== 进度条 ===== */
  272.         .progress-track {
  273.             height: 4px;
  274.             background: #f0f1f5;
  275.             border-radius: 20px;
  276.             overflow: hidden;
  277.         }
  278.         .progress-bar {
  279.             height: 100%;
  280.             background: linear-gradient(90deg, #6366f1, #8b5cf6, #22d3ee);
  281.             border-radius: 20px;
  282.             transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  283.             width: 0%;
  284.         }
  285.         /* ===== Toast ===== */
  286.         .toast {
  287.             position: fixed;
  288.             bottom: 32px;
  289.             right: 32px;
  290.             background: rgba(255, 255, 255, 0.95);
  291.             backdrop-filter: blur(16px);
  292.             border: 1px solid rgba(99, 102, 241, 0.12);
  293.             border-radius: 18px;
  294.             padding: 14px 24px;
  295.             color: #1e1e2f;
  296.             font-size: 0.85rem;
  297.             display: flex;
  298.             align-items: center;
  299.             gap: 10px;
  300.             box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.12);
  301.             opacity: 0;
  302.             transform: translateY(12px) scale(0.96);
  303.             transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  304.             pointer-events: none;
  305.             z-index: 999;
  306.         }
  307.         .toast.show {
  308.             opacity: 1;
  309.             transform: translateY(0) scale(1);
  310.             pointer-events: auto;
  311.         }
  312.         .toast i {
  313.             font-size: 1.1rem;
  314.             color: #6366f1;
  315.         }
  316.         /* ===== 状态指示器 ===== */
  317.         .status-dot {
  318.             width: 10px;
  319.             height: 10px;
  320.             border-radius: 50%;
  321.             display: inline-block;
  322.             background: #6366f1;
  323.             animation: pulse-dot 1.6s ease-in-out infinite;
  324.         }
  325.         @keyframes pulse-dot {
  326.             0%,
  327.             100% {
  328.                 opacity: 0.4;
  329.                 transform: scale(0.9);
  330.             }
  331.             50% {
  332.                 opacity: 1;
  333.                 transform: scale(1.2);
  334.             }
  335.         }
  336.         /* ===== 辅助 ===== */
  337.         .line-clamp-2 {
  338.             display: -webkit-box;
  339.             -webkit-line-clamp: 2;
  340.             -webkit-box-orient: vertical;
  341.             overflow: hidden;
  342.         }
  343.         /* ===== 响应式 ===== */
  344.         @media (max-width: 768px) {
  345.             .navbar-light .row {
  346.                 flex-direction: column;
  347.                 gap: 10px;
  348.             }
  349.             .btn-primary {
  350.                 font-size: 0.95rem;
  351.                 padding: 14px 18px;
  352.             }
  353.             .ratio-btn .label {
  354.                 font-size: 0.9rem;
  355.             }
  356.             .toast {
  357.                 bottom: 16px;
  358.                 right: 16px;
  359.                 left: 16px;
  360.                 border-radius: 14px;
  361.                 padding: 12px 18px;
  362.                 font-size: 0.8rem;
  363.             }
  364.             .result-card .actions button {
  365.                 font-size: 0.7rem;
  366.                 padding: 6px 0;
  367.             }
  368.         }
  369.         /* ===== 选择框 ===== */
  370.         select.input-light {
  371.             appearance: none;
  372.             background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  373.             background-repeat: no-repeat;
  374.             background-position: right 16px center;
  375.             padding-right: 40px;
  376.             cursor: pointer;
  377.         }
  378.         select.input-light option {
  379.             background: #ffffff;
  380.             color: #1e1e2f;
  381.         }
  382.         /* ===== 徽章 ===== */
  383.         .badge-soft {
  384.             display: inline-flex;
  385.             align-items: center;
  386.             gap: 4px;
  387.             padding: 2px 10px;
  388.             border-radius: 100px;
  389.             font-size: 0.7rem;
  390.             font-weight: 500;
  391.             background: #f0f1ff;
  392.             color: #6366f1;
  393.         }
  394.     </style>
  395. </head>
  396. <body>
  397.     <!-- ===== 顶部导航 ===== -->
  398.     <header class="navbar-light sticky top-0 z-50">
  399.         <div class="max-w-7xl mx-auto px-5 md:px-8 py-4 flex items-center justify-between gap-4 row">
  400.             <div class="flex items-center gap-4 shrink-0">
  401.                 <div class="flex items-center gap-2.5">
  402.                     <span class="w-9 h-9 rounded-xl bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center text-white font-bold text-lg shadow-sm shadow-indigo-200">✦</span>
  403.                     <span class="text-lg font-semibold tracking-tight text-gray-800">多米<span class="text-indigo-500">AI</span></span>
  404.                 </div>
  405.                 <span class="hidden sm:inline text-xs text-gray-400 font-light border-l border-gray-200/60 pl-4">图像工坊</span>
  406.             </div>
  407.             <div class="flex items-center gap-3 w-full max-w-md">
  408.                 <div class="relative flex-1">
  409.                     <i class="fas fa-key absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 text-xs"></i>
  410.                     <input id="apiKey" type="password" placeholder="API Key · 一次保存,永久使用" class="input-light pl-10 pr-4 text-sm" />
  411.                 </div>
  412.                 <button onclick="toggleKeyVisibility()" class="w-10 h-10 rounded-xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center shrink-0 transition-colors border border-gray-200/60">
  413.                     <i id="keyEye" class="fas fa-eye text-gray-500 text-sm"></i>
  414.                 </button>
  415.             </div>
  416.         </div>
  417.     </header>
  418.     <!-- ===== 主布局 ===== -->
  419.     <div class="max-w-7xl mx-auto px-5 md:px-8 py-8 flex gap-8">
  420.         <!-- ===== 侧边栏 · 历史 ===== -->
  421.         <aside class="hidden xl:block w-64 shrink-0">
  422.             <div class="card-light p-5 sticky top-28 max-h-[calc(100vh-10rem)] overflow-y-auto">
  423.                 <div class="flex items-center justify-between mb-5">
  424.                     <h3 class="text-sm font-semibold text-gray-700 flex items-center gap-2">
  425.                         <i class="fas fa-clock-rotate-left text-indigo-400 text-xs"></i> 生成历史
  426.                     </h3>
  427.                     <button onclick="clearHistory()" class="text-xs text-gray-400 hover:text-red-500 transition-colors">
  428.                         <i class="fas fa-trash-can"></i>
  429.                     </button>
  430.                 </div>
  431.                 <div id="history" class="space-y-3"></div>
  432.                 <div id="historyEmpty" class="text-center py-10 text-gray-400 text-xs">
  433.                     <i class="fas fa-image text-xl mb-3 block opacity-50"></i>
  434.                     暂无记录
  435.                 </div>
  436.             </div>
  437.         </aside>
  438.         <!-- ===== 主内容 ===== -->
  439.         <main class="flex-1 min-w-0">
  440.             <!-- Hero -->
  441.             <div class="text-center mb-10">
  442.                 <h1 class="text-4xl md:text-5xl font-extrabold tracking-tight text-gray-900 leading-tight">
  443.                     AI <span class="text-indigo-500">爆款</span>工坊
  444.                 </h1>
  445.                 <p class="mt-3 text-gray-500 text-sm md:text-base flex items-center justify-center gap-2 flex-wrap">
  446.                     <span class="badge-soft">
  447.                         <i class="fas fa-sparkles text-indigo-400 text-[10px]"></i> image2 4K
  448.                     </span>
  449.                     <span class="text-gray-300">·</span>
  450.                     <span>多种比例</span>
  451.                     <span class="text-gray-300">·</span>
  452.                     <span>海量灵感</span>
  453.                 </p>
  454.             </div>
  455.             <!-- ===== 生成卡片 ===== -->
  456.             <div class="card-light p-6 md:p-8 shadow-sm">
  457.                 <!-- 提示词 -->
  458.                 <textarea id="prompt" class="textarea-light" placeholder="描述你的爆款图片,或点击下方灵感标签一键使用 …"></textarea>
  459.                 <!-- 灵感标签库 -->
  460.                 <div class="mt-7">
  461.                     <div class="flex items-center justify-between mb-4">
  462.                         <span class="text-xs text-gray-500 flex items-center gap-2">
  463.                             <i class="fas fa-lightbulb text-amber-500/80 text-[10px]"></i> 精选灵感 · 点击即用
  464.                         </span>
  465.                         <button onclick="shufflePrompts()" class="text-xs px-4 py-1.5 rounded-full bg-gray-100 hover:bg-gray-200 text-gray-500 transition-colors flex items-center gap-1.5 border border-gray-200/60">
  466.                             <i class="fas fa-arrows-rotate text-[10px]"></i> 换一批
  467.                         </button>
  468.                     </div>
  469.                     <div id="promptLibrary" class="flex flex-wrap gap-2 max-h-44 overflow-y-auto pr-1"></div>
  470.                 </div>
  471.                 <!-- 比例 -->
  472.                 <div class="mt-7">
  473.                     <span class="text-xs text-gray-500 flex items-center gap-2 mb-3">
  474.                         <i class="fas fa-crop text-[10px]"></i> 输出比例
  475.                     </span>
  476.                     <div id="ratioButtons" class="grid grid-cols-5 gap-2.5"></div>
  477.                 </div>
  478.                 <!-- 参数行 -->
  479.                 <div class="mt-7 grid grid-cols-1 md:grid-cols-3 gap-4">
  480.                     <div>
  481.                         <label class="block text-xs text-gray-500 mb-1.5 font-medium">模型</label>
  482.                         <select id="model" class="input-light">
  483.                             <option value="gpt-image-2">image2 4K · 推荐</option>
  484.                         </select>
  485.                     </div>
  486.                     <div>
  487.                         <label class="block text-xs text-gray-500 mb-1.5 font-medium">生成数量</label>
  488.                         <select id="n" class="input-light">
  489.                             <option value="1">1 张</option>
  490.                             <option value="2" selected>2 张</option>
  491.                             <option value="4">4 张</option>
  492.                         </select>
  493.                     </div>
  494.                     <div>
  495.                         <label class="block text-xs text-gray-500 mb-1.5 font-medium">参考图像(可选)</label>
  496.                         <input id="refImage" type="text" placeholder="https://..." class="input-light text-sm" />
  497.                     </div>
  498.                 </div>
  499.                 <!-- 生成按钮 -->
  500.                 <button onclick="generateImage()" id="generateBtn" class="btn-primary mt-8">
  501.                     <i class="fas fa-bolt"></i>
  502.                     <span id="btnText">生成爆款图片</span>
  503.                 </button>
  504.             </div>
  505.             <!-- ===== 结果区域 ===== -->
  506.             <div id="resultArea" class="mt-10 hidden">
  507.                 <div class="card-light p-6 md:p-8 shadow-sm">
  508.                     <!-- 状态头 -->
  509.                     <div class="flex items-center justify-between mb-5">
  510.                         <div class="flex items-center gap-3">
  511.                             <span id="statusIcon" class="status-dot"></span>
  512.                             <div>
  513.                                 <div id="statusText" class="text-base font-semibold text-gray-800">任务提交中 …</div>
  514.                                 <div id="taskIdDisplay" class="text-[11px] text-gray-400 font-mono mt-0.5"></div>
  515.                             </div>
  516.                         </div>
  517.                         <button onclick="cancelTask()" class="text-xs px-4 py-2 rounded-xl bg-gray-100 hover:bg-red-100 text-gray-500 hover:text-red-600 transition-colors border border-gray-200/60">
  518.                             <i class="fas fa-xmark mr-1.5"></i>取消
  519.                         </button>
  520.                     </div>
  521.                     <!-- 进度 -->
  522.                     <div class="progress-track mb-8">
  523.                         <div id="progress" class="progress-bar"></div>
  524.                     </div>
  525.                     <!-- 图片网格 -->
  526.                     <div id="images" class="grid grid-cols-1 sm:grid-cols-2 gap-5"></div>
  527.                 </div>
  528.             </div>
  529.         </main>
  530.     </div>
  531.     <!-- ===== Toast ===== -->
  532.     <div id="toast" class="toast">
  533.         <i id="toastIcon" class="fas fa-check-circle"></i>
  534.         <span id="toastMsg">已完成</span>
  535.     </div>
  536.     <script>
  537.         // ============================================================
  538.         //  状态
  539.         // ============================================================
  540.         let currentTaskId = null;
  541.         let pollingInterval = null;
  542.         let history = JSON.parse(localStorage.getItem('duomi_history') || '[]');
  543.         let promptLibrary = [
  544.             "赛博朋克东京夜景,雨夜霓虹灯反射在湿漉漉的街道上,飞行汽车穿梭,超现实主义,电影级光影,4K",
  545.             "梦幻治愈系森林小屋,夕阳洒进窗户,飘浮的萤火虫,温暖色调,吉卜力风格,超详细",
  546.             "一位身穿汉服的古代女子站在长城上眺望,晨雾缭绕,金色阳光,史诗级电影感,写实摄影",
  547.             "蒸汽朋克风格的巨大飞艇在天空中航行,云海翻腾,铜管机械细节丰富,复古色彩",
  548.             "极简日式禅意庭院,枯山水,晨雾弥漫,极简构图,宁静氛围,4K超清",
  549.             "水下梦幻珊瑚城堡,彩色鱼群游弋,光线从海面穿透,魔幻现实主义",
  550.             "未来赛博格少女在霓虹城市中漫步,反射在玻璃上的全息投影,cyberpunk 2077风格",
  551.             "中国古风山水画意境,墨色淡彩,山川云雾,飞鸟点缀,国风插画大师级",
  552.             "一只戴着王冠的胖橘猫坐在宝座上,宫廷背景,搞笑奢华,卡通写实混合",
  553.             "黄金时刻的薰衣草花田,一位少女奔跑其中,长发飞扬,电影画面,温暖光影",
  554.             "黑暗奇幻:黑龙盘踞在古老城堡废墟上,月光照耀,史诗级概念艺术",
  555.             "极简产品渲染:透明玻璃香水瓶,漂浮在水面,反射梦幻光斑,工作室灯光",
  556.             "80年代复古霓虹街机厅,赛博朋克少女玩游戏,胶片颗粒,怀旧氛围",
  557.             "魔法森林中的精灵少女,长发飘逸,萤火虫环绕,梦幻光效,吉卜力+写实",
  558.             "雪山湖泊日出,镜面反射,极致风景摄影,4K国家地理级别"
  559.         ];
  560.         const ratios = [
  561.             { label: "9:16", value: "1024x1792", desc: "竖版" },
  562.             { label: "3:4", value: "1152x1536", desc: "主图" },
  563.             { label: "1:1", value: "1024x1024", desc: "正方" },
  564.             { label: "16:9", value: "1792x1024", desc: "横版" },
  565.             { label: "21:9", value: "1792x768", desc: "宽屏" }
  566.         ];
  567.         // ============================================================
  568.         //  API Key 持久化
  569.         // ============================================================
  570.         function loadApiKey() {
  571.             const saved = localStorage.getItem('duomi_api_key');
  572.             if (saved) {
  573.                 document.getElementById('apiKey').value = saved;
  574.             }
  575.         }
  576.         function saveApiKey() {
  577.             const key = document.getElementById('apiKey').value.trim();
  578.             if (key) {
  579.                 localStorage.setItem('duomi_api_key', key);
  580.             } else {
  581.                 localStorage.removeItem('duomi_api_key');
  582.             }
  583.         }
  584.         // 输入时自动保存
  585.         document.addEventListener('DOMContentLoaded', () => {
  586.             loadApiKey();
  587.             document.getElementById('apiKey').addEventListener('input', saveApiKey);
  588.         });
  589.         // 切换 Key 可见性
  590.         function toggleKeyVisibility() {
  591.             const el = document.getElementById('apiKey');
  592.             const eye = document.getElementById('keyEye');
  593.             if (el.type === 'password') {
  594.                 el.type = 'text';
  595.                 eye.className = 'fas fa-eye-slash text-gray-500 text-sm';
  596.             } else {
  597.                 el.type = 'password';
  598.                 eye.className = 'fas fa-eye text-gray-500 text-sm';
  599.             }
  600.         }
  601.         // ============================================================
  602.         //  渲染函数
  603.         // ============================================================
  604.         function renderPromptLibrary() {
  605.             const container = document.getElementById('promptLibrary');
  606.             container.innerHTML = '';
  607.             promptLibrary.forEach(text => {
  608.                 const tag = document.createElement('span');
  609.                 tag.className = 'prompt-tag';
  610.                 tag.textContent = text.length > 58 ? text.slice(0, 55) + '…' : text;
  611.                 tag.title = text;
  612.                 tag.onclick = () => {
  613.                     document.getElementById('prompt').value = text;
  614.                     showToast('灵感已加载', 'fa-lightbulb');
  615.                 };
  616.                 container.appendChild(tag);
  617.             });
  618.         }
  619.         function shufflePrompts() {
  620.             promptLibrary = promptLibrary.sort(() => Math.random() - 0.5);
  621.             renderPromptLibrary();
  622.             showToast('灵感已刷新', 'fa-arrows-rotate');
  623.         }
  624.         function renderRatios() {
  625.             const container = document.getElementById('ratioButtons');
  626.             container.innerHTML = '';
  627.             ratios.forEach((r, i) => {
  628.                 const btn = document.createElement('div');
  629.                 btn.className = `ratio-btn ${i === 3 ? 'active' : ''}`;
  630.                 btn.innerHTML = `<div class="label">${r.label}</div><div class="desc">${r.desc}</div>`;
  631.                 btn.onclick = () => {
  632.                     document.querySelectorAll('.ratio-btn').forEach(b => b.classList.remove('active'));
  633.                     btn.classList.add('active');
  634.                 };
  635.                 container.appendChild(btn);
  636.             });
  637.         }
  638.         function renderHistory() {
  639.             const container = document.getElementById('history');
  640.             const empty = document.getElementById('historyEmpty');
  641.             container.innerHTML = '';
  642.             if (!history.length) {
  643.                 empty.style.display = 'block';
  644.                 return;
  645.             }
  646.             empty.style.display = 'none';
  647.             history.slice(0, 10).forEach(item => {
  648.                 const div = document.createElement('div');
  649.                 div.className = 'history-card';
  650.                 div.innerHTML = `
  651.                     <img src="${item.images[0]}" alt="历史" loading="lazy" />
  652.                     <div class="info">
  653.                         <p>${item.prompt}</p>
  654.                     </div>
  655.                 `;
  656.                 div.onclick = () => showResult(item);
  657.                 container.appendChild(div);
  658.             });
  659.         }
  660.         // ============================================================
  661.         //  核心生成
  662.         // ============================================================
  663.         async function generateImage() {
  664.             const apiKey = document.getElementById('apiKey').value.trim();
  665.             if (!apiKey) {
  666.                 showToast('请先输入 API Key', 'fa-key');
  667.                 document.getElementById('apiKey').focus();
  668.                 return;
  669.             }
  670.             // 再次保存
  671.             localStorage.setItem('duomi_api_key', apiKey);
  672.             let prompt = document.getElementById('prompt').value.trim();
  673.             if (!prompt) {
  674.                 showToast('请输入或选择提示词', 'fa-pencil');
  675.                 return;
  676.             }
  677.             const btn = document.getElementById('generateBtn');
  678.             btn.disabled = true;
  679.             document.getElementById('btnText').innerHTML = `<i class="fas fa-spinner fa-spin"></i> 提交中 …`;
  680.             // 显示结果区
  681.             const area = document.getElementById('resultArea');
  682.             area.classList.remove('hidden');
  683.             document.getElementById('statusText').textContent = '任务已提交,正在生成 …';
  684.             document.getElementById('statusIcon').className = 'status-dot';
  685.             document.getElementById('progress').style.width = '20%';
  686.             document.getElementById('images').innerHTML = '';
  687.             // 获取当前比例
  688.             const activeRatio = document.querySelector('.ratio-btn.active');
  689.             const size = activeRatio ? activeRatio.querySelector('.label').textContent : '16:9';
  690.             const sizeMap = {
  691.                 '9:16': '1024x1792',
  692.                 '3:4': '1152x1536',
  693.                 '1:1': '1024x1024',
  694.                 '16:9': '1792x1024',
  695.                 '21:9': '1792x768'
  696.             };
  697.             const finalSize = sizeMap[size] || '1792x1024';
  698.             const payload = {
  699.                 model: 'gpt-image-2',
  700.                 prompt: prompt,
  701.                 size: finalSize,
  702.                 n: parseInt(document.getElementById('n').value)
  703.             };
  704.             try {
  705.                 const res = await fetch('https://duomiapi.com/v1/images/generations?async=true', {
  706.                     method: 'POST',
  707.                     headers: {
  708.                         'Authorization': apiKey,
  709.                         'Content-Type': 'application/json'
  710.                     },
  711.                     body: JSON.stringify(payload)
  712.                 });
  713.                 const data = await res.json();
  714.                 if (data.id) {
  715.                     currentTaskId = data.id;
  716.                     document.getElementById('taskIdDisplay').textContent = `Task: ${currentTaskId}`;
  717.                     document.getElementById('progress').style.width = '40%';
  718.                     startPolling(apiKey);
  719.                 } else {
  720.                     showToast('提交失败,请检查 API Key', 'fa-circle-exclamation');
  721.                     area.classList.add('hidden');
  722.                 }
  723.             } catch (e) {
  724.                 showToast('网络错误,请重试', 'fa-wifi-slash');
  725.                 area.classList.add('hidden');
  726.             } finally {
  727.                 btn.disabled = false;
  728.                 document.getElementById('btnText').innerHTML = `<i class="fas fa-bolt"></i> 生成爆款图片`;
  729.             }
  730.         }
  731.         function startPolling(apiKey) {
  732.             if (pollingInterval) clearInterval(pollingInterval);
  733.             let attempts = 0;
  734.             pollingInterval = setInterval(async () => {
  735.                 attempts++;
  736.                 try {
  737.                     const res = await fetch(`https://duomiapi.com/v1/tasks/${currentTaskId}`, {
  738.                         headers: { 'Authorization': apiKey }
  739.                     });
  740.                     const data = await res.json();
  741.                     if (data.state === 'succeeded') {
  742.                         clearInterval(pollingInterval);
  743.                         pollingInterval = null;
  744.                         const images = data.data.images.map(i => i.url);
  745.                         const resultData = {
  746.                             prompt: document.getElementById('prompt').value,
  747.                             images,
  748.                             ratio: '16:9'
  749.                         };
  750.                         showResult(resultData);
  751.                         saveToHistory(resultData);
  752.                         document.getElementById('progress').style.width = '100%';
  753.                         showToast('4K 爆款生成完成 🎉', 'fa-sparkles');
  754.                         document.getElementById('statusIcon').className = 'w-3 h-3 rounded-full bg-emerald-500';
  755.                         document.getElementById('statusText').innerHTML =
  756.                             '生成完成 <span class="text-emerald-600 font-semibold">✓ 4K</span>';
  757.                     } else if (data.state === 'failed') {
  758.                         clearInterval(pollingInterval);
  759.                         pollingInterval = null;
  760.                         showToast('生成失败,请重试', 'fa-circle-exclamation');
  761.                         document.getElementById('statusIcon').className = 'w-3 h-3 rounded-full bg-red-400';
  762.                         document.getElementById('statusText').textContent = '生成失败';
  763.                     } else {
  764.                         const p = Math.min(40 + attempts * 6, 92);
  765.                         document.getElementById('progress').style.width = p + '%';
  766.                         document.getElementById('statusText').textContent = `正在生成 … ${Math.round(p)}%`;
  767.                     }
  768.                 } catch (e) {
  769.                     // silent
  770.                 }
  771.             }, 2600);
  772.         }
  773.         function showResult(data) {
  774.             const container = document.getElementById('images');
  775.             container.innerHTML = '';
  776.             data.images.forEach(url => {
  777.                 const card = document.createElement('div');
  778.                 card.className = 'result-card';
  779.                 card.innerHTML = `
  780.                     <img src="${url}" alt="生成结果" loading="lazy" />
  781.                     <div class="actions">
  782.                         <button onclick="downloadImage('${url}');event.stopImmediatePropagation()">
  783.                             <i class="fas fa-download"></i> 下载
  784.                         </button>
  785.                         <button onclick="copyImageUrl('${url}');event.stopImmediatePropagation()">
  786.                             <i class="fas fa-link"></i> 复制
  787.                         </button>
  788.                     </div>
  789.                 `;
  790.                 card.onclick = () => window.open(url, '_blank');
  791.                 container.appendChild(card);
  792.             });
  793.             document.getElementById('resultArea').classList.remove('hidden');
  794.         }
  795.         function saveToHistory(data) {
  796.             history.unshift(data);
  797.             if (history.length > 20) history.pop();
  798.             localStorage.setItem('duomi_history', JSON.stringify(history));
  799.             renderHistory();
  800.         }
  801.         function clearHistory() {
  802.             if (!confirm('确定清空所有历史记录?')) return;
  803.             history = [];
  804.             localStorage.setItem('duomi_history', JSON.stringify(history));
  805.             renderHistory();
  806.             showToast('历史已清空', 'fa-trash-can');
  807.         }
  808.         // ============================================================
  809.         //  工具函数
  810.         // ============================================================
  811.         function downloadImage(url) {
  812.             const a = document.createElement('a');
  813.             a.href = url;
  814.             a.download = `domi-${Date.now()}.jpg`;
  815.             a.click();
  816.             showToast('下载已开始', 'fa-download');
  817.         }
  818.         function copyImageUrl(url) {
  819.             navigator.clipboard.writeText(url).then(() => {
  820.                 showToast('链接已复制', 'fa-link');
  821.             }).catch(() => {
  822.                 showToast('复制失败', 'fa-triangle-exclamation');
  823.             });
  824.         }
  825.         function cancelTask() {
  826.             if (pollingInterval) {
  827.                 clearInterval(pollingInterval);
  828.                 pollingInterval = null;
  829.             }
  830.             document.getElementById('resultArea').classList.add('hidden');
  831.             showToast('已取消', 'fa-ban');
  832.         }
  833.         let toastTimer = null;
  834.         function showToast(msg, icon = 'fa-check-circle') {
  835.             const toast = document.getElementById('toast');
  836.             document.getElementById('toastIcon').className = `fas ${icon}`;
  837.             document.getElementById('toastMsg').textContent = msg;
  838.             toast.classList.add('show');
  839.             clearTimeout(toastTimer);
  840.             toastTimer = setTimeout(() => toast.classList.remove('show'), 2800);
  841.         }
  842.         // ============================================================
  843.         //  初始化
  844.         // ============================================================
  845.         window.onload = () => {
  846.             renderRatios();
  847.             renderPromptLibrary();
  848.             renderHistory();
  849.             console.log('%c✦ 多米AI 图像工坊 ✦', 'color:#6366f1;font-size:18px;font-weight:600;');
  850.             console.log('%cAPI Key 已本地持久化,刷新无需重新输入', 'color:#22d3ee;font-size:12px;');
  851.         };
  852.     </script>
  853. </body>
  854. </html>
复制代码




评论1

手机用户Pd18208Lv.3 发表于 2026-4-26 22:24:56 | 查看全部 <
你这个一次只能一个任务,多个任务开始了,费用的扣了,图没给生成
回复

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 立即注册 微信登录

本版积分规则

您需要 登录 后才可以回复,轻松玩转社区,没有帐号?立即注册
快速回复
关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表