Python, converting png to gif using ImageMagick -
I am using Python 2.7.6, I had a problem converting some PNG files into GIF (an animation To create)
os.system ("Convert-dated 1-Digiage background + page" + str (output_dir) + "/*.png -loop 0" + str (output_dir) + "/ Animation GIF")
This was the error on which I have
Parametre non welde - 1
Enough to go Without error, this is only an estimate, but ...
If there is an empty space or quote in output_dir
or other special characters, to avoid or quote you Nothing is doing, so your command line will look something like this:
Convert - Day 1-digest background + page ~ / My image / *. Png -loop 0 ~ / My Photos / Animation.gif
There may be a completely valid argument for sending ~ / my
for input, and Pictures / *. PNG
is to solve a full bank Additional relative path that converts
is ready to deal with additional inputs, but then you have to ~ / My
, which is not valid because it has something similar to the input, and some additional logic as image / animation.gif
which is converted
It has been done, it has no idea.
You can say this around your problem using the repr (output_dir)
, which quotes appropriate Python-literally, which is often but It does not always be as usual, as it quotes Bash as well ... but this is a very bad idea.
A better way to do this is to give a proper quote for your Python. Docs says:
subprocess
module new processes Provides more powerful features to increase and retrieve their results; It is better to use that module to use that function.
With it, you can also give a list of arguments instead of trying to form them as a legitimate command line, and shell - though, instead of opening it you can You will need to dump.
When you are on it, it is better to use the os.path
methods instead of string methods to deal with the paths.
For example:
args = (['convert', '-delay', '1', '-dispose', 'background', '+ page '] + Glob.glob (os.path.join (output_dir,' * .png ')) + [' -loop ',' 0 ', os.path.join (output_dir,' animation .gif ')]) subprocess .check_call (args)
Or, alternatively, you can still use the shell, but then use it to quote each of your arguments, as explain the docs.
Instead of trying to create a command line to run the ImageMagick command line tool, use one of the three at the first position.
Comments
Post a Comment