python-imaging-library

Importing PPM images with python and PIL module

谁说我不能喝 提交于 2021-02-04 21:00:42
问题 EDIT: Actually, I need a way I can read the lines and extract the pixel info into some structure so I can use the putpixel function to create an image based on the ppm p3 file. I've been trying this for so long and I can't just get it right. I'm working with Python Imaging Library (PIL) and I want to open a PPM image and display it as an image on the screen. How can I do that using only PIL? this is my ppm image. it's just a 7x1 image that i created. P3 # size 7x1 7 1 255 0 0 0 201 24 24 24

Importing PPM images with python and PIL module

↘锁芯ラ 提交于 2021-02-04 21:00:16
问题 EDIT: Actually, I need a way I can read the lines and extract the pixel info into some structure so I can use the putpixel function to create an image based on the ppm p3 file. I've been trying this for so long and I can't just get it right. I'm working with Python Imaging Library (PIL) and I want to open a PPM image and display it as an image on the screen. How can I do that using only PIL? this is my ppm image. it's just a 7x1 image that i created. P3 # size 7x1 7 1 255 0 0 0 201 24 24 24

IO Error:Cannot open image while generating barcode after freezing using py2exe

断了今生、忘了曾经 提交于 2021-02-04 20:47:25
问题 I have used pyBarcode library to generate Barcode in my software and its works perfectly fine while I load it from command line but once I freeze the entire software using py2exe I am getting IO error while generating the barcode. File "panels.pyc", line 383, in generate File "barcodeGenerator.pyc", line 9, in generate File "barcode\base.pyc", line 68, in save File "barcode\codex.pyc", line 251, in render File "barcode\base.pyc", line 103, in render File "barcode\writer.pyc", line 188, in

Converting Text to Image with Unicode characters

白昼怎懂夜的黑 提交于 2021-01-29 19:46:04
问题 So, the idea here is that the given text, which happens to be Devanagari character such as संस्थानका कर्मचारी and I want to convert given text to image. Here is what I have attempted. def draw_image(myString): width=500 height=100 back_ground_color=(255,255,255) font_size=10 font_color=(0,0,0) unicode_text = myString im = Image.new ( "RGB", (width,height), back_ground_color ) draw = ImageDraw.Draw (im) unicode_font = ImageFont.truetype("arial.ttf", font_size) draw.text ( (10,10), unicode_text

How to remove whitespace from an image in Python?

六月ゝ 毕业季﹏ 提交于 2021-01-29 17:12:33
问题 I have a set of images that are output from a code, and I want to be able to remove all of the excess whitespace within the image so that it reduces the image to only the text within the image. This is the pertinent code: from PIL import Image, ImageFont, ImageDraw, ImageChops from docx import Document import textwrap import re doc = Document('Patents.docx') docText = ''.join(paragraph.text for paragraph in doc.paragraphs) def trim(im, color): bg = Image.new(im.mode, im.size, color) diff =

Frames of transparent gif overlapping with each other

这一生的挚爱 提交于 2021-01-29 14:02:23
问题 I'm trying to create a transparent gif through pillow in python through this code frames[0].save(path+'/final.gif', format='GIF', append_images=frames[1:], save_all=True, duration=33, loop=0,transparency=0) where frame is a list of PIL.Image files. The end result is that you can see the image in the previous frame This hasn't happened before and I was able to create this gif without any problems 回答1: I solved this problem by setting disposal = 2 , you can edit your code as: frames[0].save

Blending the edges of an overlaid image using python

雨燕双飞 提交于 2021-01-29 13:17:46
问题 Follow up question from Replacing a quadrilateral with a square generated from PIL.QUAD I am able to overlay the image perfectly, but want ways to blur just the edges. I took a look at composite_channel and the list of operators (http://docs.wand-py.org/en/0.4.1/wand/image.html#wand.image.COMPOSITE_OPERATORS) and while luminize seems to work well as an operator, it still does not blur the edges. Are there ways to do this with wand ? 来源: https://stackoverflow.com/questions/61276080/blending

file is not saved in particular directory using PIL im.save

对着背影说爱祢 提交于 2021-01-29 11:16:16
问题 I tried to resize some image files and save them in other directory. and there's not any error but files didn't save in directory I designated. path = r"C:\Users\abc123\Desktop\various_image" valid_images = [".jpg",".gif",".png",".tga"] for f in os.listdir(path): ext = os.path.splitext(f)[1] if ext.lower() not in valid_images: continue im = Image.open(os.path.join(path,f)) resize_im = im.resize((256, 256), Image.ANTIALIAS) ext = ".jpg" resize_im.save(r"C:\Users\abc123\Desktop\Movie" + f + ext

ImageDraw - adapt Font Size dynamically to text length

这一生的挚爱 提交于 2021-01-29 10:52:29
问题 The font size has to dynamically adapt to different the text length, which can vary a lot. Currently I have a ton of code, basically manually checking how long the incoming text is and manually giving a font size for that. There has to be a better solution. I don't think I can use ImageDraw.textsize. Has anyone a solution for this kinda problem? Thanks 回答1: I don't know other method then ImageDraw.textsize() in for -loop which checks it for different font sizes. Now I found that in version 8

Can't convert image to grayscale when using OpenCV

强颜欢笑 提交于 2021-01-29 09:04:47
问题 I have a transparent logo that I want to convert to grayscale using OpenCV. I am using the following code def to_grayscale(logo): gray = cv2.cvtColor(logo, cv2.COLOR_RGB2GRAY) blur = cv2.GaussianBlur(gray, (5, 5), 0) canny = cv2.Canny(blur, 50, 150) # sick return canny This is the image variable: brand_logo = Image.open(current_dir + '/logos/' + logo_image, 'r').convert('RGBA') brand_logo = to_grayscale(brand_logo) And this is the error: TypeError: Expected Ptr<cv::UMat> for argument 'src' I