Getting “cannot write mode P as JPEG” while operating on JPG image
You need to convert the image to RGB mode. Image.open(‘old.jpeg’).convert(‘RGB’).save(‘new.jpeg’)
You need to convert the image to RGB mode. Image.open(‘old.jpeg’).convert(‘RGB’).save(‘new.jpeg’)
For debian sudo apt install libjpeg-dev zlib1g-dev pip install Pillow
The documentation for Image.open says that it can accept a file-like object, so you should be able to pass in a io.BytesIO object created from the bytes object containing the encoded image: from PIL import Image import io image_data = … # byte values of the image image = Image.open(io.BytesIO(image_data)) image.show()
There is a bug reported for Pillow here, which indicates that libjpeg and zlib are now required as of Pillow 3.0.0. The installation instructions for Pillow on Linux give advice of how to install these packages. Note that not all of the following packages may be missing on your machine (comments suggest that only libjpeg8-dev … Read more
libjpeg-dev is required to be able to process jpegs with pillow (or PIL), so you need to install it and then recompile pillow. It also seems that libjpeg8-dev is needed on Ubuntu 14.04 If you’re still using PIL then you should really be using pillow these days though, so first pip uninstall PIL before following … Read more