pillow

Python Pillow: Make gradient for transparency

[亡魂溺海] 提交于 2020-01-04 02:36:10
问题 I have code which add gradient on image. def st(path, gradient_magnitude=2.): im = Image.open(path) if im.mode != 'RGBA': im = im.convert('RGBA') width, height = im.size gradient = Image.new('L', (width, 1), color=0xFF) for x in range(width): gradient.putpixel((x, 0), int(255 * (1 - gradient_magnitude * float(x) / width))) alpha = gradient.resize(im.size) black_im = Image.new('RGBA', (width, height), color=0x000000) black_im.putalpha(alpha) gradient_im = Image.alpha_composite(im, black_im)

how to fit image to label in Python

穿精又带淫゛_ 提交于 2020-01-03 19:40:16
问题 So in python i have a Label that I'm using to display images. But the images are rather large and they exceed the size of the label. Is there a way to load the images to fit the label without resizing them? here is what i do now. labelWidth = top.winfo_screenwidth() labelHeight = top.winfo_screenheight() maxsize = (labelWidth, labelHeight) im.thumbnail(maxsize, Image.ANTIALIAS) tkpi = ImageTk.PhotoImage(im) but this takes way to long. Thanks in advanced, I'm very new to Python. 回答1: try: im =

“Too many open files” error when opening and loading images in Pillow

∥☆過路亽.° 提交于 2020-01-03 09:03:12
问题 When running the following code: KEEP=[] for file in glob.glob("./KEEP/thing*.[tT][iI][fF]"): m = pattern.search(file) filename=m.group(1) keep=Image.open(file) keep.load() KEEP.append(keep) KEEP_NAMES.append(filename) keep.close() over more than a thousand files, I get the error message: Traceback (most recent call last): File "/hom/yannis/texmf/python/remove-harakat.py", line 123, in <module> File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 2237, in open IOError: [Errno 24]

“Too many open files” error when opening and loading images in Pillow

风格不统一 提交于 2020-01-03 09:02:46
问题 When running the following code: KEEP=[] for file in glob.glob("./KEEP/thing*.[tT][iI][fF]"): m = pattern.search(file) filename=m.group(1) keep=Image.open(file) keep.load() KEEP.append(keep) KEEP_NAMES.append(filename) keep.close() over more than a thousand files, I get the error message: Traceback (most recent call last): File "/hom/yannis/texmf/python/remove-harakat.py", line 123, in <module> File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 2237, in open IOError: [Errno 24]

python/django - “Cannot use ImageField because Pillow is not installed”

陌路散爱 提交于 2020-01-03 07:06:04
问题 I'm joining a project, so I want to set up the environnment, so what I did is : pip install -r requirements.txt This fully installed all requirements including django 1.7.0, Pillow 2.4.0 and some others. Then I want to build the database : python manage.py migrate And boom, error, I get the following : CommandError: System check identified some issues: ERRORS: stu.chan.icon: (fields.E210) Cannot use ImageField because Pillow is not installed. HINT: Get Pillow at https://pypi.python.org/pypi

Align x-ray images: find rotation, rotate and crop

你。 提交于 2020-01-03 01:44:07
问题 I want in the x-ray image below to (by using Python): identify the rotation of the (imperfect) rectangle block rotate the image so that it is in vertical (portrait form) remove by cropping the remaining white space I guess this partly the reverse of this question where the tools are most likely identical with the addition of a corner detector. I'm not entirely sure of how to best approach this and it seems like a problem that someone has solved. 回答1: This can be done using the Python bindings

Python Pillow: Add transparent gradient to an image

[亡魂溺海] 提交于 2020-01-02 22:00:27
问题 I need to add transparent gradient to an image like on the image below , I tried this: def test(path): im = Image.open(path) if im.mode != 'RGBA': im = im.convert('RGBA') width, height = im.size gradient = Image.new('L', (width, 1), color=0xFF) for x in range(width): gradient.putpixel((0 + x, 0), x) alpha = gradient.resize(im.size) im.putalpha(alpha) im.save('out.png', 'PNG') But with this I added only white gradient. How can I change color of gradient and control size of gradient. I need

PIL ImageTK not loading image in py2app application bundle

隐身守侯 提交于 2020-01-02 03:50:28
问题 I'm testing out an app that I've made which, amongst other things, loads a couple of .png images when opened. The images are displayed correctly on my Mac (10.7.5) and my mother's (10.8.5); however when my sister opens it on hers (10.9.5) the images don't load. All other functionality is otherwise intact. I should note that on my Mac and my mother's, I installed Python 3.4 and many of the packages that the app uses, including the PIL package, whereas my sister has none of these. The app was

Opening PNG with PIL/Pillow

試著忘記壹切 提交于 2020-01-02 03:00:27
问题 I'm trying to use PIL / Pillow in Python to open a PNG image. You'd think it'd be trivial, but the images are showing up corrupted. Here's an example image: I tried loading it and showing it, using Python 3.4 and Pillow 2.7.0: $ python Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import PIL.Image >>> image = PIL.Image.open(r'C:\Users\Administrator\Dropbox\Desktop

problems low contrast image(contrast stretching) in matplotlib

♀尐吖头ヾ 提交于 2020-01-01 17:25:53
问题 When reading a low-contrast image it automatically take this example: In [1]: from PIL import Image In [2]: import numpy as np In [3]: import matplotlib.pyplot as plt In [4]: img = Image.open('images/map.jpg') In [5]: arr = np.asarray(img) In [6]: plt.gray() In [7]: plt.imshow(arr) Out[7]: <matplotlib.image.AxesImage at 0x7f9c7e88f490> In [8]: plt.show() Input large Plot (no change this is automatic by matplotlib.) large Because this input is different from the plot without, modifying