Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
ImageMagick animators now can use extra_args#15739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
As a general solution for passing further argsto imagemagick when generating animations,extra_args is now actually used. Extra args areplaced after all other args, but before theoutput file name.
1b25889
tode86859
CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
looks like it's fixing an oversight to me.
Couple more thoughts:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks for the contribution. It also looks like an oversight to me, one driven by the fact that, as you noted, different tools have different argument handling and so there's no one universally safe way to add them. This looks good to me.
I'm going to go ahead and merge this because it's a correct general fix. If you'd like to submit a PR to add an explicit compression option for ImageMagick, I'd be open to that too--but I don't want to hold this fix up for that. |
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, maybethis 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