简体   繁体   中英

Python packages for editing images

I am wondering if there are any python packages out there for taking multiple graphs, saved in a png format, and editing their dimensions, and saving them in a new image? I want to have multiple graphs in a constant form, for when I have to manually add them to slides.

The standard Python imaging library for edits like these is...

well, the Python Imaging Library !

As another poster said, I'd recommend using the PIL. You could do something like this:

from PIL import Image

in_filename = 'sample.png'
out_filename = 'sample_small.png'
output_res = (320, 240)

im = Image.open(in_filename)
new_im = im.resize(output_res)
new_im.save(out_filename)

If you want to preserve the aspect ratio, you can use Image.thumbnail() instead of Image.resize(). (Note that Image.thumbnail() directly modifies the image instead of making a copy.)

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