Python Forum

Full Version: image manipulation (cropping and MetaData)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I'm looking for a lightweight python tool(s)/package to manipulate images.

Actually I just need
  • cropping
  • edition of all the metadata
  • image detection type (but maybe from mimetypes import guess_type is enough ?


So it can be one tool or dedicated tool for each.

Obviously I dig already and I discover wand & Pillow

Pillow afraid me a little because it have a lot of dependency and seem not lightweight.. ?

Maybe it is possible to do those 2 first actions with the standard python library ?? (I doubt)

Thanks.
Hi,
To get you started on questions one and two, many possibilities, try:
1) You can open the image, check it's size and resize it.
from PIL import Image
2) You can use this to check the exif, I have never used it to modify it.
import exifread
Paul
Thank you @DPaul,

Apparently PIL has been discontinued in 2011

and it seem that his "successor" pillow can also handle the exif data..

If someone know an alternatives to pillow (less dependent) I'm all ears.
(May-20-2023, 03:19 PM)SpongeB0B Wrote: [ -> ]Apparently PIL has been discontinued in 2011
It's Pillow just that it use PIL in import for backward compaltity.
(May-20-2023, 03:19 PM)SpongeB0B Wrote: [ -> ]Pillow afraid me a little because it have a lot of dependency and seem not lightweight.. ?
It's lightweight and can do all task you listed.
Example.
>>> from PIL import Image
>>>
>>> img = Image.open('forest.png')

>>> img.get_format_mimetype()
'image/png'

>>> Image.MIME[img.format]
'image/png'

# Cropping
>>> left = 155
... top = 65
... right = 360
... bottom = 270
>>> cr = img.crop((left, top, right, bottom))
>>> cr.show()
For metadata look at Edit Your Photos’ EXIF Data with Python
Thanks @snippsat

Actually for the metadata I found a really powerful way with exiftool and subprocess Amazingly fast and the most powerful :)