Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于图片输出格式的问题 #96

Open
xianzhi12345 opened this issue Jan 2, 2025 · 1 comment
Open

关于图片输出格式的问题 #96

xianzhi12345 opened this issue Jan 2, 2025 · 1 comment

Comments

@xianzhi12345
Copy link

图片默认输出格式似乎为png格式,当我放入1张jpg格式图片后,输出图片结果为png格式,但若我将jpg格式图片放入一个文件夹之后再进行超分,输出文件夹中的图片仍将保持为jpg格式。
当我开启有损压缩后,所得图片仍为png格式,而非webp或者jpeg,只有当我将有损压缩和优先将图片保存为无损webp后,得到的图片才是经过有损压缩后的webp格式。

@TransparentLC
Copy link
Owner

确定输出格式的代码在这里:

realesrgan-gui/main.py

Lines 480 to 525 in 5cfbe45

for inputPath, outputPath in zip(inputPaths, outputPaths):
inputPath = os.path.normpath(inputPath)
outputPath = os.path.normpath(outputPath)
if not os.path.exists(inputPath):
return messagebox.showwarning(define.APP_TITLE, i18n.getTranslatedString('WarningNotFoundPath'))
if os.path.isdir(inputPath):
for curDir, dirs, files in os.walk(inputPath):
for f in files:
if os.path.splitext(f)[1].lower() not in {'.jpg', '.jpeg', '.png', '.gif', '.webp', '.tif', '.tiff'}:
continue
f = os.path.join(curDir, f)
g = os.path.join(outputPath, f.removeprefix(inputPath + os.path.sep))
if os.path.splitext(f)[1].lower() == '.gif':
queue.append(task.SplitGIFTask(self.writeToOutput, self.progressValue, f, g, initialConfigParams, queue, self.varboolOptimizeGIF.get()))
elif self.varstrCustomCommand.get().strip():
t = tempfile.mktemp('.png')
queue.append(task.RESpawnTask(self.writeToOutput, self.progressValue, f, t, initialConfigParams))
queue.append(task.CustomCompressTask(self.writeToOutput, t, g, self.varstrCustomCommand.get().strip(), True))
elif self.varboolLossyMode.get() and os.path.splitext(g)[1].lower() in {'.jpg', '.jpeg', '.webp'}:
t = tempfile.mktemp('.webp')
queue.append(task.RESpawnTask(self.writeToOutput, self.progressValue, f, t, initialConfigParams))
queue.append(task.LossyCompressTask(self.writeToOutput, t, g, self.varintLossyQuality.get(), True))
else:
if os.path.splitext(f)[1].lower() in {'.tif', '.tiff'}:
g = os.path.splitext(g)[0] + ('.webp' if self.varboolUseWebP.get() else '.png')
queue.append(task.RESpawnTask(self.writeToOutput, self.progressValue, f, g, initialConfigParams))
self.progressValue[2] += 1
if not queue:
return messagebox.showwarning(define.APP_TITLE, i18n.getTranslatedString('WarningEmptyFolder'))
elif os.path.splitext(inputPath)[1].lower() in {'.jpg', '.jpeg', '.png', '.gif', '.webp', '.tif', '.tiff'}:
self.progressValue[2] += 1
if os.path.splitext(inputPath)[1].lower() == '.gif':
queue.append(task.SplitGIFTask(self.writeToOutput, self.progressValue, inputPath, outputPath, initialConfigParams, queue, self.varboolOptimizeGIF.get()))
elif self.varstrCustomCommand.get().strip():
t = tempfile.mktemp('.png')
queue.append(task.RESpawnTask(self.writeToOutput, self.progressValue, inputPath, t, initialConfigParams))
queue.append(task.CustomCompressTask(self.writeToOutput, t, outputPath, self.varstrCustomCommand.get().strip(), True))
elif self.varboolLossyMode.get() and os.path.splitext(outputPath)[1].lower() in {'.jpg', '.jpeg', '.webp'}:
t = tempfile.mktemp('.webp')
queue.append(task.RESpawnTask(self.writeToOutput, self.progressValue, inputPath, t, initialConfigParams))
queue.append(task.LossyCompressTask(self.writeToOutput, t, outputPath, self.varintLossyQuality.get(), True))
else:
queue.append(task.RESpawnTask(self.writeToOutput, self.progressValue, inputPath, outputPath, initialConfigParams))
else:
return messagebox.showwarning(define.APP_TITLE, i18n.getTranslatedString('WarningInvalidFormat'))

当我放入1张jpg格式图片后,输出图片结果为png格式

设计上是这样的,设置单个文件为输入会自动将输出路径的扩展名设为 png 或 webp(都是无损压缩),如果你需要有损压缩的话,还需要自己将输出路径的扩展名改成 jpg 或 webp(因为它也可以是有损压缩)

但若我将jpg格式图片放入一个文件夹之后再进行超分,输出文件夹中的图片仍将保持为jpg格式

输入是文件夹的话,输出的扩展名会和输入文件相同

当我开启有损压缩后,所得图片仍为png格式

输出路径是 png 的话输出的就是 png,不会进行有损压缩

只有当我将有损压缩和优先将图片保存为无损webp后,得到的图片才是经过有损压缩后的webp格式

原因就是上面的第一点和第二点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants