pillow

got OSError when use pillow to deal with my jpg image

十年热恋 提交于 2019-12-11 03:14:36
问题 I'm post a jpg picture to my website (build on django), but I got "OSError at url XXXX/XXX broken data stream when reading image file" when I use pillow to deal with it it happens when run the code in server : if request.FILES: img = request.FILES['img'] ftype = img.content_type.split('/')[1] image = Image.open(img) imagefit = ImageOps.fit(image, (200, 200), Image.ANTIALIAS) fpath = MEDIA_ROOT+'avatar/'+user.username+'.'+ftype getpath = 'avatar/'+user.username+'.'+ftype imagefit.save(fpath

Installed Pillow but still get : ModuleNotFoundError: No module named 'PIL'

这一生的挚爱 提交于 2019-12-11 02:19:58
问题 I was trying to build Fisherfaces(https://github.com/bytefish/facerec) on my Mac(OS X 10.12.6), and I successfully built its dependencies including sklearn, numpy, scipy, matplotlib except Pillow. So I tried : pip3 install Pillow at first I failed out of some network issue, so I tried again, and at last, I get this from terminal: Installing collected packages: pillow Successfully installed pillow-5.0.0 but then I tried on terminal: TreaserdeMacBook-Pro:scripts treasersmac$ python3 Python 3.6

How to get image size in python-pillow after resize?

混江龙づ霸主 提交于 2019-12-11 02:17:39
问题 resized_image = Image.resize((100,200)); Image is Python-Pillow Image class, and i've used the resize function to resize the original image, How do i find the new file-size (in bytes) of the resized_image without having to save to disk and then reading it again 回答1: The file doesn't have to be written to disk. A file like object does the trick: from io import BytesIO # do something that defines `image`... img_file = BytesIO() image.save(img_file, 'png') print(img_file.tell()) This prints the

Transparency issues drawing a rectangle with rounded corners

不羁岁月 提交于 2019-12-11 02:12:43
问题 I'm attemping to draw rectangles with rounded corners using some code I found in a tutorial, modified slightly by me: # Rounded rectangle algorithm copied from http://ju.outofmemory.cn/entry/18060 def round_corner(self, radius, fill): corner = Image.new('RGBA', (radius, radius), (0, 0, 0, 0)) draw = ImageDraw.Draw(corner) draw.pieslice((0, 0, radius * 2, radius * 2), 180, 270, fill=(fill)) return corner def round_rectangle(self, size, radius, fill): width, height = size rectangle = Image.new(

Get debug output from Pillow

风格不统一 提交于 2019-12-11 00:55:53
问题 From Python PIL incorrectly decoding TIFF colors (using incorrect colorspace)?, I infer that it used to be possible to get PIL to dump a bunch of useful debugging output by setting PIL.Image.DEBUG = True . However, this attribute no longer exists; per https://github.com/python-pillow/Pillow/issues/1191 it looks like it was replaced by usage of the built-in logging module a few years ago. However, if I do import logging logging.root.setLevel(logging.DEBUG) logging.debug('Test') # Trigger

Read the picture as a grayscale numpy array, and save it back

五迷三道 提交于 2019-12-11 00:00:31
问题 I tried the following, expecting to see the grayscale version of source image: from PIL import Image import numpy as np img = Image.open("img.png").convert('L') arr = np.array(img.getdata()) field = np.resize(arr, (img.size[1], img.size[0])) out = field img = Image.fromarray(out, mode='L') img.show() But for some reason, the whole image is pretty much a lot of dots with black in between. Why does it happen? 回答1: When you are creating the numpy array using the image data from your Pillow

UnsupportedOperation: fileno - How to fix this Python dependency mess?

泄露秘密 提交于 2019-12-10 23:43:39
问题 I'm building quite an extensive Python backend and things were working quite good on server A. I then installed the system on a new (development) server B on which I simply installed all pip packages again from scratch. Things seemed to work fine, so I did a pip freeze . I then took that list and upgraded the packages on server A. But, as you might expect I should have known better. I didn't test things on machine B wel enough, so I ran into a problem with Pillow version 3.0.0. So I

Understanding histogram() in Pillow

≡放荡痞女 提交于 2019-12-10 19:24:00
问题 From the docs: im.histogram() => list Returns a histogram for the image. The histogram is returned as a list of pixel counts, one for each pixel value in the source image. If the image has more than one band, the histograms for all bands are concatenated (for example, the histogram for an “RGB” image contains 768 values). I understand that there are 256 values for Red, 256 for Green and 256 for Blue (256 * 3 = 768). for i, value in enumerate(im.histogram()): print i, value Produces: 0 329 1

Pillow not loading image -cannot identify image file

徘徊边缘 提交于 2019-12-10 15:39:21
问题 What's wrong with the following snippet? It's not related to the image format, I tried both with jpg and png. import Image from cStringIO import StringIO with open('/path/to/file/image.png') as f: data = f.read() img = Image.open(StringIO(data)) img.load() Traceback (most recent call last): File "<stdin>", line 4, in <module> File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 2030, in open raise IOError("cannot identify image file") IOError: cannot identify image file EDIT: This

'cannot filter palette images' error when doing a ImageEnhance.Sharpness()

痞子三分冷 提交于 2019-12-10 13:48:16
问题 I have a GIF image file. I opened it using PIL.Image and did a couple of size transforms on it. Then I tried to use ImageSharpness.Enhance() on it... sharpener = PIL.ImageEnhance.Sharpness(img) sharpened = sharpener.enhance(2.0) This is causing an exception: <type 'exceptions.ValueError'> ('cannot filter palette images',) I tried to google for this error, but did not find anything. Can someone help me figure out what is going wrong? FYI the mode of the input image is 'P' . I don't have this