Cannot save GIFs with ImageMagick and Matplotlib

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Locked
Kashkawan
Posts: 1
Joined: 2020-03-23T20:56:27-07:00
Authentication code: 1152

Cannot save GIFs with ImageMagick and Matplotlib

Post by Kashkawan »

Hello,

I cannot save GIF using ImageMagick from Matplotlib since the update.
The animations also seem to not be able to be displayed anymore in Matplotlib animation tutorials.
Here is the error message I get:

Code: Select all

convert-im6.q16: unexpected end-of-file `-': No such file or directory @ error/rgb.c/ReadRGBImage/239.

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backend_bases.py", line 2785, in _wait_cursor_for_draw_cm
    self.set_cursor(cursors.WAIT)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_gtk3.py", line 468, in set_cursor
    self.canvas.get_property("window").set_cursor(cursord[cursor])
AttributeError: 'NoneType' object has no attribute 'set_cursor'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/animation.py", line 230, in saving
    yield self
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/animation.py", line 1152, in save
    writer.grab_frame(**savefig_kwargs)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/animation.py", line 385, in grab_frame
    dpi=self.dpi, **savefig_kwargs)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py", line 2203, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backend_bases.py", line 2105, in print_figure
    **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_agg.py", line 447, in print_raw
    FigureCanvasAgg.draw(self)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_agg.py", line 392, in draw
    else nullcontext()):
  File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backend_bases.py", line 2788, in _wait_cursor_for_draw_cm
    self.set_cursor(self._lastCursor)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_gtk3.py", line 468, in set_cursor
    self.canvas.get_property("window").set_cursor(cursord[cursor])
AttributeError: 'NoneType' object has no attribute 'set_cursor'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/Kashkawan/Desktop/projection/projection.py", line 204, in <module>
    anim.save('projection3.gif', dpi=80, writer='imagemagick')
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/animation.py", line 1152, in save
    writer.grab_frame(**savefig_kwargs)
  File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/animation.py", line 232, in saving
    self.finish()
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/animation.py", line 368, in finish
    self.cleanup()
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/animation.py", line 412, in cleanup
    self._proc.returncode, self._proc.args, out, err)
subprocess.CalledProcessError: Command '['convert', '-size', '640x640', '-depth', '8', '-delay', '4.0', '-loop', '0', 'rgba:-', 'projection3.gif']' returned non-zero exit status 1.
/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_gtk3.py:195: Warning: Source ID 8 was not found when attempting to remove it
  GLib.source_remove(self._idle_draw_id)
Thanks for your help,

Kawan.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cannot save GIFs with ImageMagick and Matplotlib

Post by fmw42 »

You command does not make sense to me. -size 640x640 requires a setting such as xc:"somecolor" or canvas:"somecolor. Which is 'rgba:-' and 'projection3.gif'. Is one the input and the other the output. If so, your should remove -size 640x640 and move the input to just after convert.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Cannot save GIFs with ImageMagick and Matplotlib

Post by snibgo »

On "RGBA:", see https://www.imagemagick.org/script/formats.php . That is a raw (headerless) format needing "-size" and "-depth" to be set before reading the file.

The command seems to be:

Code: Select all

convert -size 640x640 -depth 8 -delay 4.0 -loop 0 rgba:- projection3.gif 
... and that looks okay to me.

You can check that IM works properly by creating a RGBA file and trying to read it:

Code: Select all

magick rose: info:
rose: PNM 70x46 70x46+0+0 8-bit sRGB 9673B 0.000u 0:00.004

magick rose: x.rgba

cat x.rgba |magick -size 70x46 -depth 8 -delay 4.0 -loop 0 rgba:- x.gif
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cannot save GIFs with ImageMagick and Matplotlib

Post by fmw42 »

Yes. Sorry, I misunderstood the command as originally presented. Reading rgba format needs the -size and depth first in the command line.

Locked