python-imaging-library

Cropping an image in tkinter

北城以北 提交于 2020-05-23 21:33:28
问题 I'm using tkinter and I have a "sprite sheet" and I want to cut it into multiple images. I tried PIL: img = Image.open("test.png").convert("RGBA") img2 = img.crop([300,300,350,350]) image = ImageTk.PhotoImage(img2) win = tk.Tk() label = tk.Label(win, image = image) label.pack() but on my window, there is only an empty white rectangle and I don't understand why. Moreover I tried img2.show() just to make shure that img2 wasn't empty and it wasn't. 回答1: Here is your code, with a few changes.

Add padding to images to get them into the same shape

人盡茶涼 提交于 2020-05-23 04:33:07
问题 l have a set of images of different sizes (45,50,3), (69,34,3), (34,98,3) . l want to add padding to these images as follows: Take the max width and length of the whole images then put the image in that size import os import glob import cv2 input_path="/home/images" os.chdir(indput_path) images=glob.glob("*.png") Length=[] Width=[] for img in images: img=cv2.imread(img) width,length=img.shape[0:2] Length.append(length) Width.append(width) W=max(Width) L=max(Length) How can l add padding in

Convert string to image in python

给你一囗甜甜゛ 提交于 2020-05-17 06:44:06
问题 I started to learn python a week ago and want to write a small programm that converts a email to a image (.png) so that it can be shared on forums without risking to get lots of spam mails. It seems like the python standard libary doesn't contain a module that can do that but i`ve found out that there's a PIL module for it (PIL.ImageDraw). My problem is that i can't seem to get it working. So basically my questions are: How to draw a text onto a image. How to create a blank (white) image Is

How to write several image tiles, from http request, into new image object in python?

大城市里の小女人 提交于 2020-05-17 06:06:23
问题 I need to request more than 100 image tiles from a server and save it in the new empty image object in a sequence and save the result on disk. I can easily do the request and save a single image tile with the following code : image_r = requests.get('https://myserver.com') image = image_r.content with open ('image.jpg', 'wb') as f f.write(image) f.close() I have created an empty array to store all tiles from my request, but I am failing on looping over them and plotting to the new empty image

How to plot several image tiles in new emty image object based on image tile name in python?

[亡魂溺海] 提交于 2020-05-17 06:00:33
问题 I need to request several image tiles from a server and plot them in the new image object and save it as a jpg file. Image tile name starts at its position in new image object: e.g. position:x0,y0 --> Tile name: 00 I know how to do https request, and how to create new empty image objects I can use PIL: import requests from PIL import Image url = f‘https://myserver.com/GetTile/{tileKey}’ imageTile = requests.get(url) image_sheet = Image.new("RGB", (8192, 4096)) Where I have stuck is how to

Merging perspective corrected image with transparent background template image using PILLOW [PIL, Python]

陌路散爱 提交于 2020-05-17 03:08:09
问题 Problem: I have multiple book cover images. I made a template of "book"-like template with a 3D perspective. And all I have to do now its take each of book cover images, correct a perspective (its always constant, because the template is always unchanged) and merge my perspective corrected image with the template (background/canvas). For easier understanding - here is an example created in Adobe Photoshop: With red arrows I tried to show vertex points of the original cover image (before

Merging perspective corrected image with transparent background template image using PILLOW [PIL, Python]

不想你离开。 提交于 2020-05-17 03:02:12
问题 Problem: I have multiple book cover images. I made a template of "book"-like template with a 3D perspective. And all I have to do now its take each of book cover images, correct a perspective (its always constant, because the template is always unchanged) and merge my perspective corrected image with the template (background/canvas). For easier understanding - here is an example created in Adobe Photoshop: With red arrows I tried to show vertex points of the original cover image (before

Merging perspective corrected image with transparent background template image using PILLOW [PIL, Python]

删除回忆录丶 提交于 2020-05-17 03:02:07
问题 Problem: I have multiple book cover images. I made a template of "book"-like template with a 3D perspective. And all I have to do now its take each of book cover images, correct a perspective (its always constant, because the template is always unchanged) and merge my perspective corrected image with the template (background/canvas). For easier understanding - here is an example created in Adobe Photoshop: With red arrows I tried to show vertex points of the original cover image (before

Merging perspective corrected image with transparent background template image using PILLOW [PIL, Python]

让人想犯罪 __ 提交于 2020-05-17 03:01:14
问题 Problem: I have multiple book cover images. I made a template of "book"-like template with a 3D perspective. And all I have to do now its take each of book cover images, correct a perspective (its always constant, because the template is always unchanged) and merge my perspective corrected image with the template (background/canvas). For easier understanding - here is an example created in Adobe Photoshop: With red arrows I tried to show vertex points of the original cover image (before

Drawing text with PIL does not work on all images

烈酒焚心 提交于 2020-05-16 08:08:49
问题 I'm trying to draw text on images with PIL. However, I can see text on certain images only. A lot of png's don't work, such as this one: http://r0k.us/graphics/kodak/kodim16.html Code sample: import PIL from PIL import ImageFont from PIL import Image from PIL import ImageDraw from os.path import expanduser im1=Image.open(expanduser('~/Desktop/in.png')) # Drawing the text on the picture font = ImageFont.truetype('/Library/Fonts/Songti.ttc', 100) draw = ImageDraw.Draw(im1) draw.text((50, 600),