Compare images Python PIL

To check does jpg files are exactly the same use pillow library: from PIL import Image from PIL import ImageChops image_one = Image.open(path_one) image_two = Image.open(path_two) diff = ImageChops.difference(image_one, image_two) if diff.getbbox(): print(“images are different”) else: print(“images are the same”)

Python/PIL Resize all images in a folder

#!/usr/bin/python from PIL import Image import os, sys path = “/root/Desktop/python/images/” dirs = os.listdir( path ) def resize(): for item in dirs: if os.path.isfile(path+item): im = Image.open(path+item) f, e = os.path.splitext(path+item) imResize = im.resize((200,200), Image.ANTIALIAS) imResize.save(f + ‘ resized.jpg’, ‘JPEG’, quality=90) resize() Your mistake is belong to full path of the files. Instead of item … Read more

Tkinter PIL image not displaying inside of a function

It does not work inside function, since tkimg is garbage collected after function finishes. You need to bind your images into variables that wont be garbage collected. For example to global variables, or instance variables in a class, rather than local variables. To make tkimg be able to write to the global tkimg use global … Read more

create an image with border of certain width in python

I would recommend using PIL’s built-in expand() function, which allows you to add a border of any colour and width to an image. So, starting with this: #!/usr/bin/env python3 from PIL import Image, ImageOps # Open image im = Image.open(‘start.png’) # Add border and save bordered = ImageOps.expand(im, border=10, fill=(0,0,0)) bordered.save(‘result.png’) If you want different … Read more

python tkinter how to bind key to a button

You’ll need to make two changes: Add master.bind(‘s’, self.sharpen) to __init__. (Binding to the Frame, self, does not seem to work.) When s is pressed, self.sharpen(event) will be called. Since Tkinter will be sending a Tkinter.Event object, we must also change the call signature to def sharpen(self, event=None): Thus, when the button is pressed, event … Read more

How to read a raw image using PIL?

The specific documentation is at http://effbot.org/imagingbook/concepts.htm: Mode The mode of an image defines the type and depth of a pixel in the image. The current release supports the following standard modes: 1 (1-bit pixels, black and white, stored with one pixel per byte) L (8-bit pixels, black and white) P (8-bit pixels, mapped to any … Read more