Python Forum
image manipulation (cropping and MetaData)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
image manipulation (cropping and MetaData)
#1
Question 
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.
[Image: NfRQr9R.jpg]
Reply
#2
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
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#3
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.
[Image: NfRQr9R.jpg]
Reply
#4
(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
Reply
#5
Thanks @snippsat

Actually for the metadata I found a really powerful way with exiftool and subprocess Amazingly fast and the most powerful :)
[Image: NfRQr9R.jpg]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: 'function' object has no attribute 'metadata 3lnyn0 5 4,648 Mar-28-2022, 04:42 PM
Last Post: Larz60+
  Adding Language metadata to a PDF programmatically bhargavi22 0 1,950 Aug-17-2020, 12:53 PM
Last Post: bhargavi22
  METADATA Errors millpond 0 1,920 Jul-21-2020, 08:22 AM
Last Post: millpond
  How to sort image files according to a metadata file? Brahmslove 1 3,141 Dec-05-2019, 11:25 PM
Last Post: scidam
  Parse the data in XML metadata field klllmmm 2 3,278 Jun-19-2019, 04:24 PM
Last Post: klllmmm
  cropping a picture (always square) Leon 1 2,148 Aug-13-2018, 10:04 AM
Last Post: Leon
  Tiff metadata sudecki 1 19,834 Aug-10-2018, 07:08 AM
Last Post: sudecki
  Video Metadata Question malonn 10 9,507 Jul-23-2018, 04:04 PM
Last Post: malonn
  Help developing img cropping tool in python lerugray 9 6,834 Dec-20-2017, 08:07 AM
Last Post: Mekire
  image processing and manipulation 3015799 1 2,917 Nov-01-2017, 01:57 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020