Page 1 of 1

Chaining Successful Commands

Posted: 2010-02-18T08:31:57-07:00
by dunnma
I have 2 commands that function correctly independently. I have tried to use the miff command to chain them, but I get an error (below). I also cannot figure out how to "merge" them.

First: (pretty simple, just applies the overlay to image and saves as result)

Code: Select all

composite -gravity center  overlay.png  image.png  result.png
Second: (takes the result.png image and adds transparent rounded corners to it saving as final)

Code: Select all

convert result.png -resize 128x128! \
      -format 'roundrectangle 1,1 %[fx:w+0],%[fx:h+0] 10,10' \
      -write info:tmp.mvg \
      -matte -bordercolor none -border 1 \
      \( +clone -alpha transparent -background none \
         -fill white -stroke none -strokewidth 0 -draw @tmp.mvg \) \
      -compose DstIn -composite \
      \( +clone -alpha transparent -background none \) \
      -compose Over -composite final.png
  rm -f tmp.mvg
Here is the code and error from using miff:

Code: Select all

composite -gravity center  overlay.png  image.png  miff:- |\
convert -resize 128x128! \
      -format 'roundrectangle 1,1 %[fx:w+0],%[fx:h+0] 10,10' \
      -write info:tmp.mvg \
      -matte -bordercolor none -border 1 \
      \( +clone -alpha transparent -background none \
         -fill white -stroke none -strokewidth 0 -draw @tmp.mvg \) \
        -compose DstIn -composite \
      \( +clone -alpha transparent -background none \) \
      -compose Over -composite final.png

[b]Error: [/b]convert: image sequence is required `+clone' @ convert.c/ConvertImageCommand/865.
Can anyone show me how to combine these two?

Thanks!

Re: Chaining Successful Commands

Posted: 2010-02-18T08:43:14-07:00
by snibgo
"miff:" is a file format, not a command. The "-" means send it to stdout. You need a corresponding "-" in the next convert to read from stdin.

convert - -resize 128x128! \
etc

Re: Chaining Successful Commands

Posted: 2010-02-18T09:08:56-07:00
by el_supremo
An alternative method would be to do the composite within the convert command so that you don't need to call the composite command at all.
The first line of the convert would become something like this:

Code: Select all

convert -gravity center image.png overlay.png  -compose -resize 128x128! -gravity northwest\
The -gravity at the end changes the gravity back to the default so that the later composites work properly.
Also note that when using the convert program the two images of a composite are specified in the opposite order.

Pete

Re: Chaining Successful Commands

Posted: 2010-02-18T10:10:52-07:00
by dunnma
Thanks gents...I did the first thing (silly me forgot the -). Now my problem is that when I run the command from the command line it works, when I try to do it through php's shell_exec it does not. Here is my code:

Code: Select all

$output = shell_exec( "/usr/bin/composite -gravity center  /full/path/to/overlay.png  /full/path/to/image.png miff:- |\
/usr/bin/convert - -resize 128x128! \
      -format 'roundrectangle 1,1 %[fx:w+0],%[fx:h+0] 10,10' \
      -write info:tmp.mvg \
      -matte -bordercolor none -border 1 \
      \( +clone -alpha transparent -background none \
         -fill white -stroke none -strokewidth 0 -draw @tmp.mvg \) \
      -compose DstIn -composite \
      \( +clone -alpha transparent -background none \) \
      -compose Over -composite /full/path/to/test.png
  rm -f tmp.mvg");

		echo 'Output: '.$output.'<br /><br /><img src="test.png" /><br /><br />';
No image is created and there is no "output" from the command line. I have checked the permissions on both the source image and the folder being written to and even made sure they are 777 and I still get nothing. Any clue on this one?

Should I post this as a separate topic under Users?

Re: Chaining Successful Commands

Posted: 2010-02-18T10:28:45-07:00
by el_supremo
Ooops. There's a mistake in my version - it should be "-composite" not "-compose":

Code: Select all

convert -gravity center image.png overlay.png  -composite -resize 128x128! -gravity northwest\
Pete

Re: Chaining Successful Commands

Posted: 2010-02-18T11:05:31-07:00
by fmw42
I am not an expert on PHP, but it may not allow you to pipe commands. Seems like the pipe may be replacable by clones and other parens, but I have not studied your command that well.

Or perhaps you need to use exec rather than shell_exec?

One of the PHP experts needs to comment.

See my reply to viewtopic.php?f=1&t=11270&start=15#p54939 and to viewtopic.php?f=1&t=15525

They may help you.

Post a link to your input images and your good output image and we can see what to do about helping.

Re: Chaining Successful Commands

Posted: 2010-02-18T15:14:32-07:00
by snibgo
I would do the obvious things, like ensuring that some IM command works, then splitting this one into two so it doesn't use pipes, and so on.

Re: Chaining Successful Commands

Posted: 2010-02-18T15:37:29-07:00
by dunnma
Thanks for the help guys. Actually the problem is that when running it in the shell_exec function it doesn't like it broken up on multiple lines.

i.e. this doesn't work:

Code: Select all

shell_exec( "/usr/bin/composite -gravity center  /full/path/to/overlay.png  /full/path/to/image.png miff:- |\
/usr/bin/convert - -resize 128x128! \
      -format 'roundrectangle 1,1 %[fx:w+0],%[fx:h+0] 10,10' \
      -write info:tmp.mvg \
      -matte -bordercolor none -border 1 \
      \( +clone -alpha transparent -background none \
         -fill white -stroke none -strokewidth 0 -draw @tmp.mvg \) \
      -compose DstIn -composite \
      \( +clone -alpha transparent -background none \) \
      -compose Over -composite /full/path/to/test.png
  rm -f tmp.mvg");
this does:

Code: Select all

shell_exec( "/usr/bin/composite -gravity center  /full/path/to/overlay.png  /full/path/to/image.png miff:- | /usr/bin/convert - -resize 128x128! -format 'roundrectangle 1,1 %[fx:w+0],%[fx:h+0] 10,10' -write info:tmp.mvg -matte -bordercolor none -border 1 \( +clone -alpha transparent -background none -fill white -stroke none -strokewidth 0 -draw @tmp.mvg \) -compose DstIn -composite \( +clone -alpha transparent -background none \)  -compose Over -composite /full/path/to/test.png");
Notice how the second one doesn't user the \ to put things on a new line? Food for thought and hopefully this helps others down the road.

Thanks again!

Re: Chaining Successful Commands

Posted: 2010-02-18T15:52:12-07:00
by snibgo
Ah, yes, of course. "\" is bash, not PHP. And I'm not sure if you need to escape the brackets. Splitting the lines in PHP would be something like:

Code: Select all

shell_exec( <<<theEnd
  /usr/bin/composite -gravity center  /full/path/to/overlay.png  /full/path/to/image.png miff:- |
  /usr/bin/convert - -resize 128x128!
      -format 'roundrectangle 1,1 %[fx:w+0],%[fx:h+0] 10,10'
      -write info:tmp.mvg
      -matte -bordercolor none -border 1
      ( +clone -alpha transparent -background none
         -fill white -stroke none -strokewidth 0 -draw @tmp.mvg ) 
      -compose DstIn -composite 
      ( +clone -alpha transparent -background none ) 
      -compose Over -composite /full/path/to/test.png
  rm -f tmp.mvg
theEnd
);

Re: Chaining Successful Commands

Posted: 2010-02-18T16:11:20-07:00
by dunnma
Yeah...I figured that was it...although I thought that calling shell_exec would actually run the command as a bash command. Go figure. :?

Hopefully this might help out others if the come this way.