Skip to content

Prompt as Code | GPT Image 2 / 2.5 提示词与案例库,530+ 个案例、20+ 套工业级模板与可复用 Skills,新增 2.5 同提示词对比专区,附完整提示词与生成记录,持续更新。

Add generated image comparison view

freestyleflye94099835485
diff --git a/src/main.jsx b/src/main.jsx
index 69b3914..c90ab33 100644
--- a/src/main.jsx
+++ b/src/main.jsx
@@ -76,6 +76,8 @@ const copy = {
generating: 'Generating...',
editablePrompt: 'Editable Prompt',
generatedResult: 'Generated Result',
+ originalImage: 'Original Image',
+ savedInBrowser: 'Saved in this browser',
resetPrompt: 'Reset Prompt',
oneFreeGeneration: '1 free test image',
freeLimitReached: 'Free generation used. Credits are coming soon.',
@@ -147,6 +149,8 @@ const copy = {
generating: '生成中...',
editablePrompt: '可编辑 Prompt',
generatedResult: '生成结果',
+ originalImage: '原图',
+ savedInBrowser: '已保存到本浏览器',
resetPrompt: '重置 Prompt',
oneFreeGeneration: '免费生成 1 张测试图',
freeLimitReached: '免费额度已用完,积分购买即将开放。',
@@ -230,6 +234,45 @@ function compactText(value, maxLength = 180) {
return `${value.slice(0, maxLength)}...`;
}
+const GENERATED_TESTS_STORAGE_KEY = 'gpt-image-2-generated-tests:v1';
+const MAX_SAVED_GENERATIONS = 12;
+
+function readSavedGenerations() {
+ try {
+ return JSON.parse(localStorage.getItem(GENERATED_TESTS_STORAGE_KEY) || '{}');
+ } catch {
+ return {};
+ }
+}
+
+function getSavedGeneration(caseId) {
+ const saved = readSavedGenerations()[String(caseId)];
+ return saved?.image ? saved : null;
+}
+
+function saveGeneratedTest(caseId, entry) {
+ const key = String(caseId);
+ const saved = readSavedGenerations();
+ saved[key] = entry;
+
+ const latestEntries = Object.entries(saved)
+ .filter(([, value]) => value?.image)
+ .sort(([, a], [, b]) => new Date(b.savedAt || 0) - new Date(a.savedAt || 0))
+ .slice(0, MAX_SAVED_GENERATIONS);
+
+ try {
+ localStorage.setItem(GENERATED_TESTS_STORAGE_KEY, JSON.stringify(Object.fromEntries(latestEntries)));
+ } catch {
+ const compactEntries = latestEntries.slice(0, Math.max(1, Math.floor(MAX_SAVED_GENERATIONS / 2)));
+ try {
+ localStorage.setItem(GENERATED_TESTS_STORAGE_KEY, JSON.stringify(Object.fromEntries(compactEntries)));
+ } catch {
+ // Browser storage can be full or blocked. The generated image still stays
+ // visible for the current dialog state when persistence is unavailable.
+ }
+ }
+}
+
function localizeLabel(value, language, styleLibrary) {
const libraryItems = [
...(styleLibrary?.categories || []),
@@ -675,8 +718,19 @@ function PreviewDialog({
useEffect(() => {
if (preview?.type !== 'case') return;
+ const savedGeneration = getSavedGeneration(preview.item.id);
setEditablePrompt(preview.item.prompt || '');
- setGenerationState({ status: 'idle', image: '', message: '' });
+ setGenerationState(
+ savedGeneration
+ ? {
+ status: 'saved',
+ image: savedGeneration.image,
+ message: '',
+ prompt: savedGeneration.prompt || preview.item.prompt || '',
+ savedAt: savedGeneration.savedAt || ''
+ }
+ : { status: 'idle', image: '', message: '', prompt: '', savedAt: '' }
+ );
}, [preview]);
if (!preview) return null;
@@ -704,6 +758,7 @@ function PreviewDialog({
const guidance = listFor(item.guidance, language);
const pitfalls = listFor(item.pitfalls, language);
const isGenerating = generationState.status === 'generating';
+ const generatedImage = !isTemplate ? generationState.image : '';
async function handleGenerate() {
if (isTemplate || isGenerating) return;
@@ -738,8 +793,14 @@ function PreviewDialog({
throw new Error(payload.error || 'GENERATION_FAILED');
}
+ const savedAt = new Date().toISOString();
+ saveGeneratedTest(item.id, {
+ image: payload.image,
+ prompt,
+ savedAt
+ });
onFreeUsedChange(true);
- setGenerationState({ status: 'success', image: payload.image, message: '' });
+ setGenerationState({ status: 'success', image: payload.image, message: '', prompt, savedAt });
} catch (error) {
setGenerationState({
status: 'error',
@@ -761,8 +822,24 @@ function PreviewDialog({
<button className="previewClose" type="button" onClick={onClose} aria-label={t.closePreview}>
<X size={20} />
</button>
- <div className="previewMedia">
- <img src={image} alt={imageAlt} />
+ <div className={cx('previewMedia', generatedImage && 'hasComparison')}>
+ {generatedImage ? (
+ <div className="comparisonGrid">
+ <figure className="comparisonFigure">
+ <div className="comparisonLabel">{t.originalImage}</div>
+ <img src={image} alt={imageAlt} />
+ </figure>
+ <figure className="comparisonFigure generatedFigure">
+ <div className="comparisonLabel">
+ {t.generatedResult}
+ {generationState.status === 'saved' ? <span>{t.savedInBrowser}</span> : null}
+ </div>
+ <img src={generatedImage} alt={t.generatedResult} />
+ </figure>
+ </div>
+ ) : (
+ <img src={image} alt={imageAlt} />
+ )}
</div>
<div className="previewContent">
<div className="previewMeta">
@@ -841,12 +918,6 @@ function PreviewDialog({
{generationState.status === 'error' ? (
<p className="generationMessage">{generationState.message}</p>
) : null}
- {generationState.image ? (
- <figure className="generatedResult">
- <img src={generationState.image} alt={t.generatedResult} />
- <figcaption>{t.generatedResult}</figcaption>
- </figure>
- ) : null}
</div>
) : null}
{isTemplate && (guidance.length || pitfalls.length || item.exampleCases?.length) ? (
diff --git a/src/styles.css b/src/styles.css
index 60cb432..c667583 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -1102,6 +1102,64 @@ button {
box-shadow: 0 24px 90px rgba(0, 0, 0, 0.48);
}
+.previewMedia.hasComparison {
+ align-items: center;
+ padding: 18px;
+}
+
+.comparisonGrid {
+ display: grid;
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ gap: 14px;
+ width: 100%;
+}
+
+.comparisonFigure {
+ display: grid;
+ grid-template-rows: auto 1fr;
+ min-width: 0;
+ margin: 0;
+ overflow: hidden;
+ border: 1px solid rgba(255, 255, 255, 0.14);
+ border-radius: 8px;
+ background: rgba(3, 7, 15, 0.62);
+ box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
+}
+
+.generatedFigure {
+ border-color: rgba(120, 255, 185, 0.24);
+ background: rgba(120, 255, 185, 0.05);
+}
+
+.comparisonLabel {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 10px;
+ min-height: 42px;
+ border-bottom: 1px solid rgba(255, 255, 255, 0.1);
+ padding: 0 12px;
+ color: #e8f7ff;
+ font-size: 12px;
+ font-weight: 900;
+}
+
+.comparisonLabel span {
+ color: #9cf7c5;
+ font-size: 11px;
+ font-weight: 800;
+ white-space: nowrap;
+}
+
+.comparisonFigure img {
+ width: 100%;
+ height: min(62vh, 620px);
+ max-height: none;
+ border-radius: 0;
+ object-fit: contain;
+ box-shadow: none;
+}
+
.previewContent {
overflow: auto;
padding: 30px;
@@ -1471,6 +1529,14 @@ button {
max-height: 58vh;
}
+ .comparisonGrid {
+ grid-template-columns: 1fr;
+ }
+
+ .comparisonFigure img {
+ height: min(48vh, 520px);
+ }
+
.previewContent {
overflow: visible;
}
@@ -1591,6 +1657,14 @@ button {
padding: 12px;
}
+ .previewMedia.hasComparison {
+ padding: 12px;
+ }
+
+ .comparisonFigure img {
+ height: min(44vh, 420px);
+ }
+
.previewContent {
padding: 20px 16px;
}