Can these processes be done at once

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
kereilly
Posts: 9
Joined: 2015-09-09T14:38:19-07:00
Authentication code: 1151

Can these processes be done at once

Post by kereilly »

I'm writing a script where i'm processing a lot of images. I create 4 files for each batch of images and I only need the last. i'm wondering if i can condense what i'm doing. Here is the first command:

Code: Select all

convert f1.png f2.png f3.png f4.png f5.png -evaluate-sequence Min -threshold 60% -negate output.png
this is the first step. But from here i only need two pieces of the image

Code: Select all

convert output.png -crop 80x35+90+40 left.png
convert output.png -crop 220x35+420+40 right.png
Now i'd like them to be one image again so i do

Code: Select all

convert -append left.png right.png final.png
Now i've created output.png, left.png, right.png and final.png. I can just erase all those with my script but can i do the cropping and appending within my first line? Seems it would save me time when doing lots of these. Thanks for the help.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Can these processes be done at once

Post by snibgo »

Untested, but I think this will work. I've split it into lines for ease of reading. Your script language will need a special character at line-ends.

Code: Select all

convert
  f1.png f2.png f3.png f4.png f5.png
  -evaluate-sequence Min -threshold 60% -negate
  ( -clone 0 -crop 80x35+90+40 )
  ( -clone 0 -crop 220x35+420+40 )
  delete 0
  -append
  final.png
snibgo's IM pages: im.snibgo.com
kereilly
Posts: 9
Joined: 2015-09-09T14:38:19-07:00
Authentication code: 1151

Re: Can these processes be done at once

Post by kereilly »

Thanks for the post. Probably should have stated i'm on a Mac and i'm running Version: ImageMagick 6.9.0-0 Q16 x86_64 2015-07-27
When i tried your code i get a bash error '(' unexpected syntax. When i take the Parentheses out i get this:

convert: geometry does not contain image `f1.png' @ warning/transform.c/CropImage/666.
convert: unable to open image `delete': No such file or directory @ error/blob.c/OpenBlob/2709.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
convert: unable to open image `0': No such file or directory @ error/blob.c/OpenBlob/2709.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.

Also is the second clone still supposed to be 0 or should it be 1? and i should delete before i append? Sorry real novice at Imagemagick. Not sure what i'm doing here. Seems if i delete the clones their is nothing to append?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Can these processes be done at once

Post by snibgo »

Bash requires that parentheses are escaped: \( and \) . (That's a feature of bash, not ImageMagick.) Put an escape character \ at the end of each line.

I wrote "delete" when I should have written "-delete". (With a minus.) Sorry.

"-delete 0" deletes image zero from the list, so the two clones will remain, to be appended.
snibgo's IM pages: im.snibgo.com
kereilly
Posts: 9
Joined: 2015-09-09T14:38:19-07:00
Authentication code: 1151

Re: Can these processes be done at once

Post by kereilly »

That did it! Thank you very much sir
Post Reply