简体   繁体   English

在 python 枕头模块中编辑后如何保存具有不同名称和不同编号的图像

[英]How do you save images with a different name and varying numbers after editing in python pillow module

We were tasked to figure out what was wrong with a code concerning batch image processing.我们的任务是找出有关批量图像处理的代码有什么问题。 And the saving part got me confused...保存部分让我感到困惑......

enhancedImg = ImageEnhance.Contrast(image)
enhancedImg.enhance(.8).save("photo-" + count + "-edited.jpg")

if count = imageFiles.length
    break
else:
    count++

What do you think is wrong with this?你认为这有什么问题?

your code is kind to unclear to me tried to grasp its aim and reproduce it somehow.你的代码对我来说有点不清楚,试图掌握它的目标并以某种方式重现它。

given input image:给定输入图像:

image-2.jpg

I have:我有:

from PIL import Image, ImageEnhance,ImageDraw,ImageFont


image = Image.open('image-2.jpg')


enhancer = ImageEnhance.Sharpness(image)


enance = []
for i in range(100):
    factor = i / 4.0
    enance.append(factor)
    
# print(enance)
    

for j in enance:

    img = enhancer.enhance(j) 
    
    img_draw = ImageDraw.Draw(img)
    
    font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/Ubuntu-C.ttf", 100)
    
    img_draw.text((70, 250), f"Sharpness {j:f}", font = font, fill='red')
    img.show()
    img.save("photo-" + str(j) + "-edited.jpg")

first output file:第一个 output 文件: photo-24.75-edited.jpg

last output file:最后 output 文件: photo-24.75-edited.jpg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM