In Python, how do I read the exif data for an image?

You can use the _getexif() protected method of a PIL Image. import PIL.Image img = PIL.Image.open(‘img.jpg’) exif_data = img._getexif() This should give you a dictionary indexed by EXIF numeric tags. If you want the dictionary indexed by the actual EXIF tag name strings, try something like: import PIL.ExifTags exif = { PIL.ExifTags.TAGS[k]: v for k, … Read more

How to show PIL Image in ipython notebook

Updated 2021/11/17 When using PIL/Pillow, Jupyter Notebooks now have a display built-in that will show the image directly, with no extra fuss. display(pil_im) Jupyter will also show the image if it is simply the last line in a cell (this has changed since the original post). Thanks to answers from @Dean and @Prabhat for pointing … Read more

Combine several images horizontally with Python

You can do something like this: import sys from PIL import Image images = [Image.open(x) for x in [‘Test1.jpg’, ‘Test2.jpg’, ‘Test3.jpg’]] widths, heights = zip(*(i.size for i in images)) total_width = sum(widths) max_height = max(heights) new_im = Image.new(‘RGB’, (total_width, max_height)) x_offset = 0 for im in images: new_im.paste(im, (x_offset,0)) x_offset += im.size[0] new_im.save(‘test.jpg’) Test1.jpg Test2.jpg … Read more

How to merge a transparent png image with another image using PIL

from PIL import Image background = Image.open(“test1.png”) foreground = Image.open(“test2.png”) background.paste(foreground, (0, 0), foreground) background.show() First parameter to .paste() is the image to paste. Second are coordinates, and the secret sauce is the third parameter. It indicates a mask that will be used to paste the image. If you pass a image with transparency, then … Read more

How to convert a NumPy array to PIL image applying matplotlib colormap

Quite a busy one-liner, but here it is: First ensure your NumPy array, myarray, is normalised with the max value at 1.0. Apply the colormap directly to myarray. Rescale to the 0-255 range. Convert to integers, using np.uint8(). Use Image.fromarray(). And you’re done: from PIL import Image from matplotlib import cm im = Image.fromarray(np.uint8(cm.gist_earth(myarray)*255)) with … Read more

Python Image Library fails with message “decoder JPEG not available” – PIL

libjpeg-dev is required to be able to process jpegs with pillow (or PIL), so you need to install it and then recompile pillow. It also seems that libjpeg8-dev is needed on Ubuntu 14.04 If you’re still using PIL then you should really be using pillow these days though, so first pip uninstall PIL before following … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)