Opened 7 years ago

Closed 7 years ago

#3367 closed defect (fixed)

g.gui.animation: animated GIF export generates corrupted GIF files

Reported by: neteler Owned by: grass-dev@…
Priority: normal Milestone: 7.2.2
Component: wxGUI Version: svn-releasebranch72
Keywords: g.gui.animation Cc:
CPU: x86-64 Platform: Linux

Description

When exporting an animated GIF, the generated file is corrupted:

# using GRASS 7.2.2svn (nc_climate_spm_2000_2012): > 
g.region raster=2002_10_precip -p

g.gui.animation `g.list raster pattern="2*_10_precip" sep=comma`
Default TGIS driver / database set to:
driver: sqlite
database: $GISDBASE/$LOCATION_NAME/$MAPSET/tgis/sqlite.db
WARNING: Temporal database connection defined as:
         /home/mneteler/grassdata/nc_climate_spm_2000_2012/climate_1970_2012/tgis/sqlite.db
         But database file does not exist.
Creating temporal database:
/home/mneteler/grassdata/nc_climate_spm_2000_2012/climate_1970_2012/tgis/sqlite.db
/home/mneteler/software/grass72/dist.x86_64-pc-linux-gnu/etc/python/grass/imaging/images2gif.py:344: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
  im2 = im[y0:y1, x0:x1]

(not sure if the warning matters)

ls -la bla.gif 
-rw-r--r-- 1 mneteler mneteler 1561325 Jul  6 14:55 bla.gif

display bla.gif 
display: corrupt image `bla.gif' @ error/gif.c/ReadGIFImage/1368.

System:

System Info                                                                     
GRASS version: 7.2.2svn                                                         
GRASS SVN revision: r71233M                                                     
Build date: 2017-07-03                                                          
Build platform: x86_64-pc-linux-gnu                                             
GDAL: 2.1.2                                                                     
PROJ.4: 4.9.2                                                                   
GEOS: 3.5.0                                                                     
SQLite: 3.14.2                                                                  
Python: 2.7.13                                                                  
wxPython: 3.0.2.0                                                               
Platform: Linux-4.11.3-202.fc25.x86_64-x86_64-with-fedora-25-Twenty_Five

Attachments (1)

noisy.gif (49.4 KB ) - added by martinl 7 years ago.

Download all attachments as: .zip

Change History (23)

comment:1 by neteler, 7 years ago

CPU: Unspecifiedx86-64
Platform: UnspecifiedLinux
Version: unspecifiedsvn-releasebranch72

comment:2 by annakrat, 7 years ago

Resolution: fixed
Status: newclosed

In 71243:

pythonlib: fix #3367 - creating gif files

comment:3 by annakrat, 7 years ago

Resolution: fixed
Status: closedreopened

It automatically closed it, please test and I will backport it then.

in reply to:  3 comment:4 by veroandreo, 7 years ago

Replying to annakrat:

It automatically closed it, please test and I will backport it then.

After updating (make distclean ; svn up && sh config_grass7.sh && make), I still get a corrupted gif from g.gui.animation.

display prueba.gif 
display: corrupt image `prueba.gif' @ error/gif.c/ReadGIFImage/1368.

System Info

GRASS version: 7.3.svn                                                          
GRASS SVN revision: r71243M                                                     
Build date: 2017-07-08                                                          
Build platform: x86_64-pc-linux-gnu                                             
GDAL: 2.1.2                                                                     
PROJ.4: 4.9.2                                                                   
GEOS: 3.5.0                                                                     
SQLite: 3.14.2                                                                  
Python: 2.7.13                                                                  
wxPython: 3.0.2.0                                                               
Platform: Linux-4.11.8-200.fc25.x86_64-x86_64-with-fedora-25-Twenty_Five 

in reply to:  3 comment:5 by hellik, 7 years ago

Replying to annakrat:

It automatically closed it, please test and I will backport it then.

tested here with

GRASS version: 7.3.svn                                                          
GRASS SVN revision: r71243                                                      
Build date: 2017-07-08                                                          
Build platform: x86_64-pc-linux-gnu                                             
GDAL: 2.2.0                                                                     
PROJ.4: 4.9.3                                                                   
GEOS: 3.5.1                                                                     
SQLite: 3.16.2                                                                  
Python: 2.7.13                                                                  
wxPython: 3.0.2.0                                                               
Platform: Linux-4.9.0-3-amd64-x86_64-with-debian-9.0 
display gguitest2.gif 
display-im6.q16: corrupt image `gguitest2.gif' @ error/gif.c/ReadGIFImage/1386.

comment:6 by annakrat, 7 years ago

My gifs are ok... Could you test this code snippet to see if the problem is in the images2gif (likely)? Also do you have Pillow or PIL?

import os
from PIL import Image
from grass.imaging import writeGif

color_path = os.path.join(os.environ['GISBASE'], "docs", "html", "colortables")
pil_images = [Image.open(os.path.join(color_path, c)) for c in os.listdir(color_path)]
writeGif('/tmp/test.gif', pil_images, duration=0.2, repeat=True)

in reply to:  6 comment:7 by hellik, 7 years ago

Replying to annakrat:

My gifs are ok... Could you test this code snippet to see if the problem is in the images2gif (likely)? Also do you have Pillow or PIL?

import os
from PIL import Image
from grass.imaging import writeGif

color_path = os.path.join(os.environ['GISBASE'], "docs", "html", "colortables")
pil_images = [Image.open(os.path.join(color_path, c)) for c in os.listdir(color_path)]
writeGif('/tmp/test.gif', pil_images, duration=0.2, repeat=True)

lines above tested

display test.gif 
display-im6.q16: corrupt image `test.gif' @ error/gif.c/ReadGIFImage/1386.

the same error

in reply to:  6 comment:8 by hellik, 7 years ago

Replying to annakrat:

Also do you have Pillow or PIL?

python-pil 4.0.0-4

comment:9 by veroandreo, 7 years ago

I tested the code in the python console of GRASS GUI. The output gif gives the same error as before.

I have python2-pillow-3.4.2-1

comment:10 by annakrat, 7 years ago

Could you test any of the available versions of images2gif.py files from different repositories? I found couple for example:

https://bitbucket.org/bench/images2gif.py/raw/a618bd8fc352f278a3b0c777cb6427ec39236f0a/images2gif.py

https://github.com/isaacgerg/images2gif/blob/master/images2gif.py

https://gist.github.com/jonschoning/7216290

https://github.com/rec/echomesh/blob/master/code/python/external/images2gif.py

If you replace the import with

from images2gif import writeGif

then the test code snippet should work.

in reply to:  10 comment:11 by hellik, 7 years ago

Replying to annakrat:

Could you test any of the available versions of images2gif.py files from different repositories? I found couple for example:

https://bitbucket.org/bench/images2gif.py/raw/a618bd8fc352f278a3b0c777cb6427ec39236f0a/images2gif.py

https://github.com/isaacgerg/images2gif/blob/master/images2gif.py

https://gist.github.com/jonschoning/7216290

https://github.com/rec/echomesh/blob/master/code/python/external/images2gif.py

If you replace the import with

from images2gif import writeGif

then the test code snippet should work.

tested here with

System Info                                                                     
GRASS version: 7.3.svn                                                          
GRASS SVN revision: r71251                                                      
Build date: 2017-07-09                                                          
Build platform: x86_64-w64-mingw32                                              
GDAL: 2.2.1                                                                     
PROJ.4: 4.9.3                                                                   
GEOS: 3.5.0                                                                     
SQLite: 3.17.0                                                                  
Python: 2.7.5                                                                   
wxPython: 2.8.12.1                                                              
Platform: Windows-8-6.2.9200 (OSGeo4W) 

and no change in images2gif.

the gif is exported, but it's not displayed correctly. only the first frame is shown and the next frames are white

in reply to:  10 comment:12 by hellik, 7 years ago

Replying to annakrat:

Could you test any of the available versions of images2gif.py files from different repositories? I found couple for example:

https://bitbucket.org/bench/images2gif.py/raw/a618bd8fc352f278a3b0c777cb6427ec39236f0a/images2gif.py

https://github.com/isaacgerg/images2gif/blob/master/images2gif.py

https://gist.github.com/jonschoning/7216290

https://github.com/rec/echomesh/blob/master/code/python/external/images2gif.py

tested here on windows all these images2gif.py, none of them worked.

comment:13 by annakrat, 7 years ago

I tested it on standalone winGRASS and OSGEO4W and it works in the standalone one, but not in OSGEO4W. It seems they use different PIL library, so that must be the difference. I will look into it later.

comment:14 by annakrat, 7 years ago

In 71258:

pythonlib: add PIL native implementation available since Pillow 3.4.0, see #3367

comment:15 by annakrat, 7 years ago

So, after some digging around, it seems to stop working since Pillow version 3.4.0 and I haven't found anywhere a working version of images2gif.py and I haven't been able to find the problem. But since 3.4.0 Pillow itself allows to write GIFs, so I added it there. Now depending on your PIL/Pillow and Pillow version, either the old or the native Pillow way is used. The problem is the GIF created by Pillow looks worse, but I don't know what could be done here. Also we could use imagemagick as a backend if it's installed and available. Anyway, please test.

comment:16 by veroandreo, 7 years ago

Tested here having python2-pillow-3.4.2-1. Now, it works, but as you say the GIF doesn't look so good in terms of definition of the images. They look noisy, as when you increase ISO in the camera.

in reply to:  16 ; comment:17 by martinl, 7 years ago

Replying to veroandreo:

Tested here having python2-pillow-3.4.2-1. Now, it works, but as you say the GIF doesn't look so good in terms of definition of the images. They look noisy, as when you increase ISO in the camera.

I can confirm it. I have python-pil 4.2.1-1. See attachment:noisy.gif created by

import os
from PIL import Image
from grass.imaging import writeGif

color_path = os.path.join(os.environ['GISBASE'], "docs", "html", "colortables")
pil_images = [Image.open(os.path.join(color_path, c)) for c in os.listdir(color_path)]
writeGif('/tmp/test.gif', pil_images, duration=0.2, repeat=True)

by martinl, 7 years ago

Attachment: noisy.gif added

comment:18 by martinl, 7 years ago

In 71481:

pythonlib: see #3367 - creating gif files (merge r71243 from trunk)

comment:19 by martinl, 7 years ago

In 71482:

pythonlib: add PIL native implementation available since Pillow 3.4.0, see #3367 (merge r71258 from trunk)

in reply to:  17 ; comment:20 by annakrat, 7 years ago

Replying to martinl:

Replying to veroandreo:

Tested here having python2-pillow-3.4.2-1. Now, it works, but as you say the GIF doesn't look so good in terms of definition of the images. They look noisy, as when you increase ISO in the camera.

I can confirm it. I have python-pil 4.2.1-1. See attachment:noisy.gif created by

import os
from PIL import Image
from grass.imaging import writeGif

color_path = os.path.join(os.environ['GISBASE'], "docs", "html", "colortables")
pil_images = [Image.open(os.path.join(color_path, c)) for c in os.listdir(color_path)]
writeGif('/tmp/test.gif', pil_images, duration=0.2, repeat=True)

Could you test r71485? I used quantize function and it seems better.

in reply to:  20 comment:21 by martinl, 7 years ago

Replying to annakrat:

Could you test r71485? I used quantize function and it seems better.

yes, much more better! Please backport. Thanks!

comment:22 by annakrat, 7 years ago

Resolution: fixed
Status: reopenedclosed

Done in r71486.

Note: See TracTickets for help on using tickets.