Imagemagick throws error when using skeptick, not CLI
abeering opened this issue · comments
So I got an interesting problem here.. I'm doing a somewhat complex combination of effects at once, making several compositions, overlaying / multiplying them, while reducing opacities and converting to jpg.
command = convert(to: 'foo.jpg') do
compose('over') do
image 'C1_L0_Leg_Metal_Arc_Chrome.png'
image 'C1_L1_001.png'
end
compose('over') do
clone(0)
image 'C1_L2_001.png'
end
delete(0)
compose('over') do
clone(0)
image 'C1_L3_001.png'
end
delete(0)
compose('multiply') do
clone(0)
convert do
image 'C1_L5_017.png'
set '-alpha', 'on'
set '-channel', 'a'
set '-evaluate', 'multiply 0.5'
set '+channel'
end
end
set '-compose', 'over'
set '-composite'
set '-background', 'White'
set '-layers', 'Flatten'
end
The command translates to:
Skeptick::Convert("convert ( C1_L0_Leg_Metal_Arc_Chrome.png C1_L1_001.png -compose over -composite ) ( -clone 0 C1_L2_001.png -compose over -composite ) -delete 0 ( -clone 0 C1_L3_001.png -compose over -composite ) -delete 0 ( -clone 0 ( C1_L5_017.png -alpha on -channel a -evaluate multiply 0.5 +channel ) -compose multiply -composite ) -compose over -composite -background White -layers Flatten foo.jpg")
When run via Skeptick, ImageMagick produces an error:
Skeptick::ImageMagickError: ImageMagick error
convert: invalid argument for option '-evaluate': +channel @ error/convert.c/ConvertImageCommand/1515.
However, if I take the exact command output by skeptick, and run on CLI, Imagemagick doesn't error.
% convert \( C1_L0_Leg_Metal_Arc_Chrome.png C1_L1_001.png -compose over -composite \) \( -clone 0 C1_L2_001.png -compose over -composite \) -delete 0 \( -clone 0 C1_L3_001.png -compose over -composite \) -delete 0 \( -clone 0 \( C1_L5_017.png -alpha on -channel a -evaluate multiply 0.5 +channel \) -compose multiply -composite \) -compose over -composite -background White -layers Flatten foo.jpg
Have we seen anything like this before? I'm wondering what could be causing it, and I'm coming up blank.
Curious if anyone has any ideas.
Update on this, it seems to be that the argument to evaluate
has a space in it. For some reason this isn't a problem on CLI, but if I remove specifically that option and replace it with another which has no space, everything works.
In fact, this works without issue:
system command.to_s.gsub('(', '\(').gsub(')', '\)')
I would guess this is some strange shell interaction, but it's strange that the same number of parens/nesting works just fine if I remove this one option. 🤔
Closing this. I can hack around it, did not see this on the README:
Watch out for the fact that it shell-escapes every argument, so if you write set '-resize foo', you will get an error, since the space will be escaped, and shell would treat that whole string as single word.
Hey I believe that I use shellescape so strings with spaces are treated as if you put them in quotes in shell. If you write set '-evaluate', 'multiply', '0.5'
it should work.
Btw, any time you use set
, you could pass a symbol and it is treated as a dashed argument.
set :alpha, 'on'
set :channel, 'a'
set :evaluate, 'multiply', '0.5'