ImageMagick animators now can use extra_args #15739
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As a general solution for passing further args
to imagemagick when generating animations,
extra_args is now actually used. Extra args are
placed after all other args, but before the
output file name.
PR Summary
Note: This is a "general solution" to the problem I had.
My usecase: I found that if I passed a generated .gif back to Imagemagick, with the args
-layers Optimize
(more fully just:convert anim.gif -layers Optimize anim.gif
), My several-megabyte gifs would be reduced in size by ~10x. In my current usage, I do this second pass via subprocess.I then went ahead and modified my local copy of matplotlib (caveat: v1.5.1 with pyhon2.7 on ubuntu 14.04; but the code looks identical between master and 1.51).
With the fix in this PR, I can now do
anim.save(gif_path, dpi=80, writer='imagemagick', extra_args=["-layers", "Optimize"])
. This works fine giving visually identical animations, and further reduces file size another order of magnitude (in the one case I'm dealing with, I'm getting a resulting file 1/70th the size).A concern I have (as I am not a regular imagemagick user, let alone an expert) is whether simply dumping extra args to image magick at the end of the hardcoded args is reasonable, or if order of operations is likely to make a mess with certain additional imagemagick arguments/operations... I might argue that any user adding imagemagick args probably knows what they're doing and would realize what's up. (I definitely benefited from
matplotlib.debug=helpful
or something like that, which showed theconvert
command that was actually invoked.) Alternately, maybe this is a spot where it's desirable to have more detailed documentation?For reference, the code where
convert
is invoked with args looks like:Therefore I am completely open to revising/redoing this PR and instead adding a
ImageMagick[File]Writer
specific arg/property e.g.compress
that explicitly adds-layers Optimize
to the command (and leaveextra_args
unused as it currently is).Other notes:
_args()
function instead.PR Checklist
extra_args