Error in images2gif.py with GlobalPalette - python-imaging-library

Getting an error when trying to convert sequence of jpgs to gifs. Can't seem to figure out how to add a palette, or if that's the actual problem. Was able to get gifs to load using the numpy arrays in the images2gif.py main.
import PIL
from PIL import Image
import StringIO
import images2gif
images = []
for frame in animation1.frames:
img_data = s3manager.get_file_as_string(frame.s3_filename)
image = Image.open(StringIO.StringIO(img_data))
images.append(image)
images2gif.writeGif('lala3.gif', images, duration=0.5, dither=0)
With this I get the following error:
"images2gif.py", line 436, in writeGifToFile
fp.write(globalPalette)
TypeError: must be string or buffer, not None
Not sure how to specify a palette for these jpgs. documentation unclear to me, and not even sure if that's the issue. help?

In images2gif.py change line 200:
for im in images:
palettes.append( getheader(im)[1] )
to
for im in images:
palettes.append(im.palette.getdata()[1])

images2gif author seems to be willing to drop support for pillow. See this thread :
https://code.google.com/p/visvis/issues/detail?id=81
From this thread too, i found a fixed version of that script, which works with me (with pillow 2.4). It is available here :
https://github.com/rec/echomesh/blob/master/code/python/external/images2gif.py and produces good quality gif with any kind of PNG (P mode too)

images2gif.py uses getheader function from PIL.GifImagePlugin to get the palettes.
For some reason, it doesn't work with image you read. Maybe the script doesn't really work if source images are not 'P' mode.

I installed PIL after Pillow and it started to work. Seems like both libraries are needed for some reason. Here is how to reinstall both:
pip uninstall PIL
pip uninstall Pillow
pip install Pillow
pip install PIL

Related

RED lines under libraries names

I just finished downloading pillow library and when i came to pycharm and type " import PIL " still underlined by red, saying " no module named PIL ". i've checked on youtube how i bring pillow's functions i am correct its " import PIL " i've checked even on the site it makes me think im wrong i lost my self confidence cause i can't fix it im in the same position for 2 weeks help please
i beleived that maybe 3.10 vesrion of python doesn't match with pillow library so i deleted it and i've downloaded 3.9 and i don't know im confused im lost

How can I fix the attribute error in VS code when the same code runs perfectly on colab?

I was running the PySINDy package and I kept on getting the module not found-error when I ran this:
pip install pysindy
import pysindy as ps
I fixed this by downgrading the Python in my VS code to 3.8.9. But I do get the following note:
note: This error originates from a subprocess, and is likely not a problem with pip.Note: you may need to restart the kernel to use updated packages.
I am now getting the attribute error when I run the following:
differentiation_method = ps.FiniteDifference(order=2)
Here's the error:
AttributeError: module 'pysindy' has no attribute 'differentiation'
Can someone please help me with this? (I successfully ran the entire code earlier on google colab and the online Jupyter, but I am unable to do it locally. I use MAC os and Jupyter via VS Code.)

'Assertion failed' error while using node-canvas

I want to use node-canvas and when I try to render text, I get this Error:
Assertion failed: (!scaled_font->cache_frozen), function
_cairo_scaled_glyph_page_destroy, file cairo-scaled-font.c, line 459. Abort trap: 6
Here some sample code:
ctx.fillStyle = 'black'
ctx._setFont(Weight, Style, FontSize, 'px', 'Arial')
ctx.fillText("Hello, World!", 50, 50)
.fillText crashed all the time, with the same error.
Maybe it's a problem with cario. Not sure what's going wrong there.
My set up:
Mac OS 10.13.6, canvas#^2.0.0-alpha.17 and installed the packages via brew install pkg-config cairo pango libpng jpeg giflib librsvg.
I wrote some comment at github here: node-canvas
I find this post on github. When i use node canvas-prebuilt it works for me. Then there is no problem with text rendering.
It means installing canvas-prebuild with npm install canvas-prebuilt and load the module with require('canvas-prebuilt').

PIL thinks every image I give it is corrupted

I'm trying to get an array of RGB values for a jpeg. Using the code
from PIL import Image
im = Image.open('lion.jpg')
pix = list(im.getdata())
gives the error
IOError: broken data stream when reading image file
The picture in the code is this one, which I got from google for testing:
but the code returns the same error for every picture I've tried, from a variety of sources (google, phone, etc...). When I push forward and load the image anyway, all the pixel values are black.
I've tried doing
from PIL import Image, ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
but all that does is suppress the error; the pixel values are still black.
It seems other people have had this problem elsewhere, like here, but so far other solutions have failed me. Any suggestions?
I'm on Mac 10.10, with python 2.7.8. I first installed Pillow with pip, and then from the source. I have confirmed that libjpeg is installed.
I don't really have an answer, but I can give you the setup of mine for which this is working fine.
The following script:
from PIL import Image
if __name__ == '__main__':
im = Image.open('lion.jpg'))
pix = list(im.getdata())
print('The image has {} pixels'.format(len(pix)))
import PIL, sys
print('Using Python version {}'.format(sys.version))
print('Using PIL version {}'.format(PIL.VERSION))
print('Using Pillow version {}'.format(PIL.PILLOW_VERSION))
Gives as a result on my Macbook with OS X El Capitan (10.11.6):
The image has 1183000 pixels
Using Python version 3.5.1 |Continuum Analytics, Inc.| (default, Dec 7 2015, 11:24:55)
[GCC 4.2.1 (Apple Inc. build 5577)]
Using PIL version 1.1.7
Using Pillow version 3.1.0
Process finished with exit code 0

IOError: cannot identify image file

Can anyone tell why PIL can't open this PNG file?
https://b75094855c6274df1cf8559f089f485661ae1156.googledrive.com/host/0B56ak7W-HmqAX005c3g5eTlBakE/8.png
I get IOError: cannot identify image file, and by looking at the code, it seems it tries PIL.PngImagePlugin.PngImageFile and corresponding "accept" function, and it returns False
I'm using version 1.1.6
I don't know what the problem is with PIL 1.1.6 but I just tested it with the latest Pillow 2.4.0 and this worked:
>>> from PIL import Image
>>> im = Image.open("8.png")
>>> im.show()
PIL in unmaintained and Pillow is an actively maintained and developed fork. To use Pillow, first uninstall PIL, then install Pillow.
Further installation instructions here: http://pillow.readthedocs.org/en/latest/installation.html
try to import cv2
>>> from PIL import Image
>>> import cv2
>>> im = cv2.imread("8.png")
>>> im = cv2.imwrite("8.png")
i hope its working...