python-imaging-library

Cropping image - Image.crop function not working

心已入冬 提交于 2021-01-27 07:19:32
问题 I have following line of code for image cropping im = Image.open('path/to/image.jpg') outfile = "path/to/dest_img.jpg" im.copy() im.crop((0, 0, 500, 500)) im.thumbnail(size, Image.ANTIALIAS) im.save(outfile, "JPEG") But it doesn't seems cropping image. I have bigger image size e.g. 2048 x 1536 px. [edited] Here's solution too, I could not answer this question myself so adding answer here. Actually crop return image with new handler, I realized where I make mistake. I should have assign crop

Cropping image - Image.crop function not working

邮差的信 提交于 2021-01-27 07:16:37
问题 I have following line of code for image cropping im = Image.open('path/to/image.jpg') outfile = "path/to/dest_img.jpg" im.copy() im.crop((0, 0, 500, 500)) im.thumbnail(size, Image.ANTIALIAS) im.save(outfile, "JPEG") But it doesn't seems cropping image. I have bigger image size e.g. 2048 x 1536 px. [edited] Here's solution too, I could not answer this question myself so adding answer here. Actually crop return image with new handler, I realized where I make mistake. I should have assign crop

Extract key frames from GIF using Python

给你一囗甜甜゛ 提交于 2021-01-27 06:59:29
问题 I want to compress a GIF image by extracting 15 frames from the GIF that preferably should be distinct. I'm using Python and Pillow library and I didn't find any way to get the number of frames a GIF has in the Pillow docs. Neither did I find how to extract a specific frame from a GIF, because Pillow restricts that. Is there any way to extract frames without iterating through each frame consequently? Is there a more advanced Python library for GIF processing? 回答1: For the number of frames,

Extract key frames from GIF using Python

拜拜、爱过 提交于 2021-01-27 06:56:53
问题 I want to compress a GIF image by extracting 15 frames from the GIF that preferably should be distinct. I'm using Python and Pillow library and I didn't find any way to get the number of frames a GIF has in the Pillow docs. Neither did I find how to extract a specific frame from a GIF, because Pillow restricts that. Is there any way to extract frames without iterating through each frame consequently? Is there a more advanced Python library for GIF processing? 回答1: For the number of frames,

Python PIL Image in Label auto resize

烂漫一生 提交于 2021-01-26 20:31:07
问题 I'm trying to make a widget to hold an image that will automatically resize to fit its container, e.g. if packed directly into a window, then expanding that window will expand the image. I have some code that is semi functional but I've had to add a couple of constants into one of the routines to prevent the auto resize from re triggering itself (causing it to keep growing in size) I'm sure that the reason for this is due to the widgets internal padding/border, but even trying to take that

PIL : PNG image as watermark for a JPG image

泪湿孤枕 提交于 2021-01-20 19:42:58
问题 I'm trying to make a composite image from a JPEG photo (1600x900) and a PNG logo with alpha channel (400x62). Here is a command that does the job with image magick: composite -geometry +25+25 watermark.png original_photo.jpg watermarked_photo.jpg Now I'd like to do something similar in a python script, without invoking this shell command externally, with PIL. Here is what I tried : photo = Image.open('original_photo.jpg') watermark = Image.open('watermark.png') photo.paste(watermark, (25, 25)

How to show PIL Image in ipython notebook

谁说胖子不能爱 提交于 2021-01-16 04:39:29
问题 This is my code from PIL import Image pil_im = Image.open('data/empire.jpg') I would like to do some image manipulation on it, and then show it on screen. I am having problem with showing PIL Image in python notebook. I have tried: print pil_im And just pil_im But both just give me: <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=569x800 at 0x10ECA0710> 回答1: You can use IPython's Module: display to load the image. You can read more from the Doc. from IPython.display import Image pil

How can I get the width and height of a text that was Image.Draw-drawn on a picture?

◇◆丶佛笑我妖孽 提交于 2021-01-16 03:50:24
问题 enter image description hereThere are already a few questions, that sound quite similar to this one on stackoverflow, but their focuses are a little bit different from what I want to know. I pasted a text on an image using ImageDraw from the Python Image Library. My question now is: Is there a way to find out the width and height of the text as a whole? For myself imagine the text to have kind of a rectangular frame. I want to get the measurements of this text-field. Can my text1 be treated

ValueError: Attempt to convert a value (<PIL.PngImagePlugin.PngImageFile image mode=RGB size=519x600 at 0x7F95AD916518>) with an unsupported type

十年热恋 提交于 2021-01-04 05:29:48
问题 while i was opening and decoding an image from python with tensorflow i got an error %tensorflow_version 2.x import tensorflow as tf from PIL import Image import requests from io import BytesIO response = requests.get(r'https://upload.wikimedia.org/wikipedia/commons/e/e9/Felis_silvestris_silvestris_small_gradual_decrease_of_quality.png') img = Image.open(BytesIO(response.content)) tf_image = tf.io.read_file(img) error is hapenning when i used tf.io.read_file(img) Throws error of

how to display PIL image with pygame?

拈花ヽ惹草 提交于 2021-01-02 20:30:16
问题 I am trying to do some video stream from my raspberry pi over the wifi. I used pygame, because i also have to use gamepad in my project. Unfortunately I stucked on displaying received frame. Shortly: i get jpeg frame, open it with PIL, convert to string - after that i can load image from string image_stream = io.BytesIO() ... frame_1 = Image.open(image_stream) f = StringIO.StringIO() frame_1.save(f, "JPEG") data = f.getvalue() frame = pygame.image.fromstring(frame_1,image_len,"RGB") screen