python-imaging-library

Rendering a float array to 24-bit RGB image (using PIL for example)

醉酒当歌 提交于 2021-02-18 11:44:09
问题 x is a numpy.float32 array, with values from -200 to 0 . These are dB (decibel) values. When I do (as recommended here): Image.fromarray(x, mode='F') I get a greyscale or sometimes nearly black image. How to map a float in [-200, 0] to a 24-bit RGB byte array (using a colormap) that can be read with the Python module PIL with Image.fromarray(x, mode='RGB') ? Edit: The required .wav audio file is here, for which we want to plot the spectrogram. Here is some code to test: import scipy, numpy as

Dynamic resizing of image using PIL and tkinter

风格不统一 提交于 2021-02-17 06:34:32
问题 I wanted to know if it was possible to resize the image dynamically(maintaining its aspect ratio). I made an image viewer app, but then the vertically long images overflow the screen, so i wanted to know a method to resize image, ive tried a way and its included below. But still im getting the same output that overflows the screen. from win32api import GetSystemMetrics from tkinter import * screen_width, screen_height = GetSystemMetrics(0), GetSystemMetrics(1) root = Tk() # this is your

Python: combine two PNG files as layers [duplicate]

放肆的年华 提交于 2021-02-16 14:38:22
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: How to merge a transparant png image with another image using PIL I have a couple of PNG files: http://dl.dropbox.com/u/6599273/testing/image1.png http://dl.dropbox.com/u/6599273/testing/image2.png As you can see, those images have transparent parts. When you put one on top each other they will form a nice looking image. Here, the composed image: http://dl.dropbox.com/u/6599273/testing/image_composed.png I

Wrap text and adjust font to container in PIL?

北城余情 提交于 2021-02-15 07:50:57
问题 I want to create a program for making a bingo, and I have everything set up except putting the text, which may range from a single word to even a whole sentence, into each field. How would I go about wrapping that text and adjusting the font size so it fits into each field? 回答1: I don't know of a way of auto-sizing text with PIL, but you can do it with wand. I am not that experienced with wand , but you can use the caption() method if you want your text auto-wrapped and sized. I changed the

Wrap text and adjust font to container in PIL?

◇◆丶佛笑我妖孽 提交于 2021-02-15 07:50:39
问题 I want to create a program for making a bingo, and I have everything set up except putting the text, which may range from a single word to even a whole sentence, into each field. How would I go about wrapping that text and adjusting the font size so it fits into each field? 回答1: I don't know of a way of auto-sizing text with PIL, but you can do it with wand. I am not that experienced with wand , but you can use the caption() method if you want your text auto-wrapped and sized. I changed the

Show an image with omxiv direct from memory on RPI

亡梦爱人 提交于 2021-02-13 17:29:31
问题 I want to create an image in PILLOW and show it on the screen on the Raspberry Pi with for example omxiv direct from memory without saving it to the memory card, something like this: Python 2.7: from PIL import Image import os img = Image.new('RGB', size=(150, 50), color=(0, 0, 255)) .... im_file = ???? os.system('omxiv im_file') Can anybody tell me how to do this? 回答1: I did some experiments with the framebuffer on my Raspberry Pi 4. Here is what I managed to work out... You can get the

Show an image with omxiv direct from memory on RPI

喜欢而已 提交于 2021-02-13 17:27:03
问题 I want to create an image in PILLOW and show it on the screen on the Raspberry Pi with for example omxiv direct from memory without saving it to the memory card, something like this: Python 2.7: from PIL import Image import os img = Image.new('RGB', size=(150, 50), color=(0, 0, 255)) .... im_file = ???? os.system('omxiv im_file') Can anybody tell me how to do this? 回答1: I did some experiments with the framebuffer on my Raspberry Pi 4. Here is what I managed to work out... You can get the

what is the correct way to override the save method in django?

扶醉桌前 提交于 2021-02-11 17:22:52
问题 I have an image model where I can upload images and I want to optimize them with pillow, I did that but there is three problems: the images doesn't get saved in the correct folder. django has a feature when there is two files with the same name django adds a random string to its name but now with two images with the same name only one gets uploaded. the original images gets uploaded too. class Images(models.Model): image1 = models.ImageField(upload_to='images/%Y/', validators=

what is the correct way to override the save method in django?

核能气质少年 提交于 2021-02-11 17:21:56
问题 I have an image model where I can upload images and I want to optimize them with pillow, I did that but there is three problems: the images doesn't get saved in the correct folder. django has a feature when there is two files with the same name django adds a random string to its name but now with two images with the same name only one gets uploaded. the original images gets uploaded too. class Images(models.Model): image1 = models.ImageField(upload_to='images/%Y/', validators=

Cannot open .tif file due to 'cannot identify image file' error

一世执手 提交于 2021-02-11 14:56:26
问题 The file exists, path is correct, however I cannot load the .tif file. Please send help? Here's the code .. import os from PIL import Image name = 'PE-0D8-4m-10s-0001_00009_bbo.tif' THIS_FOLDER = os.path.dirname(os.path.abspath(__file__)) filename = os.path.join(THIS_FOLDER, name) image = Image.open(filename) And here's the traceback: Traceback (most recent call last): File "C:\Users\owner\MATLAB Drive\Python\imageload.py", line 23, in <module> image = Image.open(filename) File "C:\Users