Page 1 of 1

Can this be combined into one command?

Posted: 2014-02-11T08:52:54-07:00
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

Re: Can this be combined into one command?

Posted: 2014-02-11T09:21:08-07:00
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.

Re: Can this be combined into one command?

Posted: 2014-02-11T13:07:23-07:00
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.

Re: Can this be combined into one command?

Posted: 2014-02-11T13:36:01-07:00
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.