Page 1 of 1

Selecting piped images

Posted: 2015-11-08T22:49:26-07:00
by AlicanC
I wrote a program that does this and it works perfectly:

Code: Select all

{ convert rose: miff:-; convert rose: -colorspace gray miff:-; } \
  | convert miff:- +append result.png
Now I have a line like this which I have to use it with piped images:

Code: Select all

convert one.png \( two.png +level 50x100% -blur '0x5' \) -compose multiply -composite result.png
I have tried these two and both failed:

Code: Select all

{ convert rose: miff:-; convert rose: -colorspace gray miff:-; } \
  | convert miff:- \( miff:- +level 50x100% -blur '0x5' \) -compose multiply -composite result.png

convert: improper image header `/var/tmp/magick-71624xtFCjx32DkrZ' @ error/miff.c/ReadMIFFImage/510.

{ convert rose: miff:-; convert rose: -colorspace gray miff:-; } \
  | convert miff:-[0] \( miff:-[1] +level 50x100% -blur '0x5' \) -compose multiply -composite result.png

convert: improper image header `/var/tmp/magick-716281IPGsqH7SEAO' @ error/miff.c/ReadMIFFImage/510.
convert: no images defined `result.png' @ error/convert.c/ConvertImageCommand/3212.
A workaround is this, but it looks ugly:

Code: Select all

{ convert rose: miff:-; convert rose: -colorspace gray miff:-; } \
  | convert miff:- \( -clone 1 +level 50x100% -blur '0x5' \) -delete 1 -compose multiply -composite result.png
Is there a better way to achieve this?

Re: Selecting piped images

Posted: 2015-11-08T23:03:51-07:00
by snibgo
It may look ugly but it is correct.

"convert miff:-" reads all the images that are available from stdin. There are no more images for another "miff:-" to read.

An alternative is to do the level and blur in the convert before the pipe.

Re: Selecting piped images

Posted: 2015-11-09T00:54:44-07:00
by fmw42
Does this do what you want?

Code: Select all

(
convert rose: \( -clone 0 -colorspace gray \) miff:- 
) | convert - \( -clone 0 \) \( -clone 1 +level 50x100% -blur '0x5' \) \
-delete 0,1 -compose multiply -composite result.png   
or simpler

Code: Select all

convert rose: \( -clone 0 -colorspace gray +level 50x100% -blur '0x5' \) \
-compose multiply -composite result.png
Or am I misunderstanding what you desired to do? Why must it have piped input?

Re: Selecting piped images

Posted: 2015-11-09T21:41:20-07:00
by AlicanC
fmw42 wrote:Or am I misunderstanding what you desired to do? Why must it have piped input?
I am actually implementing your "spot" script on JavaScript. Unlike in your scripts, I can't afford to write files in each step so I keep MIFFs in memory.

Take this command from the "spot" script for an example:

Code: Select all

convert \( $tmpA1 -define distort:viewport=${www}x${hhh}+0+0 -virtual-pixel mirror -distort SRT 0 \
	-scale ${xmin}x${ymin}! -scale ${www}x${hhh}! -crop ${ww}x${hh}+0+0 +repage \) \
	\( $tmpA2 -write mpr:tile +delete -size ${ww}x${hh}! tile:mpr:tile \) \
	-alpha off -compose copy_opacity -composite -compose over \
	-background $bgcolor -flatten  \
	"$outfile"
Your script reads images from the file system, but my program can't do that because the images are actually in memory.

Re: Selecting piped images

Posted: 2015-11-10T00:19:02-07:00
by fmw42
Can't you just fold the processing for $tmpA2 into a parentheses section where you have $tmpA2. But what does this have to do with piping? You should avoid piping and just fold all the commands together into one big command line.

Re: Selecting piped images

Posted: 2015-11-11T07:28:02-07:00
by AlicanC
fmw42 wrote:Can't you just fold the processing for $tmpA2 into a parentheses section where you have $tmpA2. But what does this have to do with piping? You should avoid piping and just fold all the commands together into one big command line.
I could, but I didn't since you didn't.

What you do in your scripts is:

Code: Select all

- Read input, write temp.
- If some parameter given, read temp, do something, write temp.
- If some parameter given, read temp, do something, write temp.
- If some parameter given, read temp, do something, write temp.
...
- Read temp, write output.
and not:

Code: Select all

- Start generating a big command line.
- If some parameter given, add "do something" to command line.
- If some parameter given, add "do something" to command line.
- If some parameter given, add "do something" to command line.
...
- Read input, run the big command line with multiple "do something"s, write output.
I could follow the second method when I port your scripts to JavaScript, but I'm not an ImageMagick god and I would probably waste a lot of time trying to debug my ports. That's why I try to make my ports as close to the originals as possible. Though I might have to do this since the scripts are also ridiculously slow when it comes to applying them to 100-200 frame MIFFs.

Maybe the real solution is IM7 scripts, but I haven't found any documentation on them and have no idea what they are capable of.

Re: Selecting piped images

Posted: 2015-11-11T10:06:07-07:00
by fmw42
I save temps because I often have multiple options and conditionals before the next step. But if you know exactly what you want, then it is better to just fold them together into one larger command line. Or if conditionals, then repeat the code for each conditional and avoid the temps.