简体   繁体   中英

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: photo-24.75-edited.jpg

last output file: photo-24.75-edited.jpg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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