Can this be combined into one command?

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
aporthog
Posts: 37
Joined: 2012-05-30T08:24:46-07:00
Authentication code: 13

Can this be combined into one command?

Post by aporthog »

I'm taking portions of a single image, resizing them and combining them into a new composite image. Right now I'm creating temporary files and I think that's causing me some problems. I'm getting sporadic, unreproduceable errors like "convert.exe: LZWDecode: Strip 0 not terminated with EOI code", "convert.exe: Not enough data at scanline 2 (short 1209 bytes)". I suspect that the operations may not have a chance to write to disk before the next operation tries to read them. Especially since it doesn't happen to the same image twice and seems to be more of a problem when the load is heavier. I've added some pauses in the program which might solve the problem but I'd like to eliminate the temporary file step in any event. My question is is there a way to eliminate the temporary files and directly generate the composite image?

Code: Select all

convert bitonal.tif -depth 24 -crop 600x800+696+1031 -compress LZW center.tif
convert bitonal.tif -depth 24 -crop 300x1200+1692+1118 -gravity west -background blue -splice 3x0 -gravity east -background black -splice 40x0 -resize 20x800^ -compress LZW edge.tif
convert center.tif edge.tif -depth 24 +append composite.jpg
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Can this be combined into one command?

Post by snibgo »

"-depth 24" is wrong. The only valid values are 8 or 16 (bits/channel/pixel). As you are saving to jpg, you don't need "-depth".

I have chopped it into lines to make it easier to read. Adjust for your script language (bash or BAT or whatever).

Code: Select all

convert 
  bitonal.tif 
  ( -clone 0 -crop 600x800+696+1031 )
  ( -clone 0 -crop 300x1200+1692+1118
    -gravity west -background blue -splice 3x0
    -gravity east -background black -splice 40x0
    -resize 20x800^
  )
  -delete 0
  +append
  composite.jpg
EDIT: Put "+" instead of "-". Sorry.
snibgo's IM pages: im.snibgo.com
aporthog
Posts: 37
Joined: 2012-05-30T08:24:46-07:00
Authentication code: 13

Re: Can this be combined into one command?

Post by aporthog »

Hey that works. And I understand it too since I've been reading up on parentheses. Well, mostly. I understand the -clones make in-memory copies of specific files from the list (which in this case has only a single element, bitonal.tif). I'm not sure what the -delete does here. Why do we need to delete the first of the two clones (if that is what -delete 0 does). And what is +append working on exactly? I could see that maybe it appends the two clones together but you went ahead and deleted one of them first. Wait, I answered my own question. -delete 0 removes the first image of the entire sequence which is bitonal.tif (not the first clone). So it is in fact the two remaining clones which get appended.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Can this be combined into one command?

Post by snibgo »

Yes, that's it. We have bitonal.tiff, counted as image number 0. We clone image 0 (and the clone is number 1). We again clone number 0, so this becomes number 2. Our list has numbers 0, 1 and 2. We delete number 0, so the two cloned versions now become numbers 0 and 1. We append these together.
snibgo's IM pages: im.snibgo.com
Post Reply