|
31 | 31 | import warnings
|
32 | 32 |
|
33 | 33 | import numpy as np
|
| 34 | +from PIL import Image |
34 | 35 |
|
35 | 36 | import matplotlib as mpl
|
36 | 37 | from matplotlib._animation_data import (
|
@@ -296,7 +297,6 @@ def __init__(self, fps=5, codec=None, bitrate=None, extra_args=None,
|
296 | 297 |
|
297 | 298 | super().__init__(fps=fps, metadata=metadata, codec=codec,
|
298 | 299 | bitrate=bitrate)
|
299 |
| - |
300 | 300 | self.frame_format = 'rgba'
|
301 | 301 | self.extra_args = extra_args
|
302 | 302 |
|
@@ -467,6 +467,10 @@ def frame_format(self, frame_format):
|
467 | 467 | if frame_format in self.supported_formats:
|
468 | 468 | self._frame_format = frame_format
|
469 | 469 | else:
|
| 470 | + cbook._warn_external( |
| 471 | + f"Ignoring file format {frame_format!r} which is not " |
| 472 | + f"supported by {type(self).__name__}; using " |
| 473 | + f"{self.supported_formats[0]} instead.") |
470 | 474 | self._frame_format = self.supported_formats[0]
|
471 | 475 |
|
472 | 476 | def _base_temp_name(self):
|
@@ -529,7 +533,6 @@ def setup(self, fig, outfile, dpi=None):
|
529 | 533 | self._frames = []
|
530 | 534 |
|
531 | 535 | def grab_frame(self, **savefig_kwargs):
|
532 |
| - from PIL import Image |
533 | 536 | buf = BytesIO()
|
534 | 537 | self.fig.savefig(
|
535 | 538 | buf, **{**savefig_kwargs, "format": "rgba", "dpi": self.dpi})
|
@@ -744,15 +747,18 @@ class ImageMagickFileWriter(ImageMagickBase, FileMovieWriter):
|
744 | 747 |
|
745 | 748 | Frames are written to temporary files on disk and then stitched
|
746 | 749 | together at the end.
|
747 |
| -
|
748 | 750 | """
|
749 | 751 |
|
750 | 752 | supported_formats = ['png', 'jpeg', 'ppm', 'tiff', 'sgi', 'bmp',
|
751 | 753 | 'pbm', 'raw', 'rgba']
|
752 | 754 |
|
753 | 755 | def _args(self):
|
754 |
| - return ([self.bin_path(), '-delay', str(self.delay), '-loop', '0', |
755 |
| - '%s*.%s' % (self.temp_prefix, self.frame_format)] |
| 756 | + # Force format: ImageMagick does not recognize 'raw'. |
| 757 | + fmt = 'rgba:' if self.frame_format == 'raw' else '' |
| 758 | + return ([self.bin_path(), |
| 759 | + '-size', '%ix%i' % self.frame_size, '-depth', '8', |
| 760 | + '-delay', str(self.delay), '-loop', '0', |
| 761 | + '%s%s*.%s' % (fmt, self.temp_prefix, self.frame_format)] |
756 | 762 | + self.output_args)
|
757 | 763 |
|
758 | 764 |
|
|
0 commit comments