Page 1 of 1

Adding multiple images to a background image

Posted: 2008-06-14T05:25:36-07:00
by bbunlock
Hi and thanks for taking the time read this, I am trying to add multiple images to a background image, I have this working fine if I do each image to be added one at a time, but that means running the command serveral times in order for it to work, I was hoping to do it all in one command but I get a bit of a mess as a result.

Here is the code I have tried to use but it just doesnt work, the images all see to be in the same place.

Code: Select all

	$command = $imageMagickPath."composite -geometry +16+1 {$mainPath}{$clock} {$mainPath}{$output} {$mainPath}{$output} "
	." composite -geometry +1+1 {$mainPath}{$signal1} {$mainPath}{$output} {$mainPath}{$output} "
	." composite -geometry +224+1 {$mainPath}{$signal2} {$mainPath}{$output} {$mainPath}{$output} "
	." composite -geometry +5+82 {$mainPath}{$icon_select} {$mainPath}{$output} {$mainPath}{$output} "
	." composite -geometry +7+83 {$mainPath}{$icon1} {$mainPath}{$output} {$mainPath}{$output} "
	." composite -geometry +45+83 {$mainPath}{$icon2} {$mainPath}{$output} {$mainPath}{$output} "
	." composite -geometry +82+83 {$mainPath}{$icon3} {$mainPath}{$output} {$mainPath}{$output} "
	." composite -geometry +122+83 {$mainPath}{$icon4} {$mainPath}{$output} {$mainPath}{$output} "
	." composite -geometry +160+83 {$mainPath}{$icon5} {$mainPath}{$output} {$mainPath}{$output} "
	." composite -geometry +200+83 {$mainPath}{$icon6} {$mainPath}{$output} {$mainPath}{$output} "
	." composite -geometry +7+130 {$mainPath}{$icon7} {$mainPath}{$output} {$mainPath}{$output}";
	
	exec($command);
basicaly its opening the output file ( the background image) adding an icon image to it and saving it as output, overwriting the original output, then move onto the next image to add and then the next etc, at least thats the effect im looking for.

there are no effects added to the images they are simply placed on the output image in the correct position using the -geometry +?+?, very similar to what adobe photoshop would do via layers.

I have looked at god knows how many examples to do this but im just not getting it to work using one command like above, however it does work if I do each image serperate like below.

Code: Select all

		// add the clock
		$command = $imageMagickPath."composite -geometry +16+1 "
              		." {$mainPath}{$clock} {$mainPath}{$output} {$mainPath}{$output}";              		
		exec($command);
		
		
		
		// add the signal strenghs
		$command = $imageMagickPath."composite -geometry +1+1 "
              		." {$mainPath}{$signal1} {$mainPath}{$output} {$mainPath}{$output}";              		
		exec($command);
		
		$command = $imageMagickPath."composite -geometry +224+1 "
              		." {$mainPath}{$signal2} {$mainPath}{$output} {$mainPath}{$output}";              		
		exec($command);

etc etc
could anyone pleae tell me where im going wrong? ive been at this for over 2 days now and i have looked at god knows how many examples and posts but no joy, so have asked for help as a last resort (cos im just not getting anywhere)

any help appriciated

regards

Re: Adding multiple images to a background image

Posted: 2008-06-14T06:17:59-07:00
by Bonzo
Composite only works with 2 images you want to use convert. I have not tried it all in one comand but see what happens if you change your code to:

Code: Select all

<?php
$command = "convert {$mainPath}{$clock} "
   ." {$mainPath}{$signal1} -geometry +1+1 -composite "
   ." {$mainPath}{$signal2} -geometry +224+1 -composite "
   ." {$mainPath}{$icon_select} -geometry +5+82 -composite "
   ." {$mainPath}{$icon1} -geometry +7+83 -composite "
   ." {$mainPath}{$icon2} -geometry +45+83 -composite "
   ." {$mainPath}{$icon3} -geometry +82+83 -composite "
   ." {$mainPath}{$icon4} -geometry +122+83 -composite "
   ." {$mainPath}{$icon5} -geometry +160+83 -composite "
   ." {$mainPath}{$icon6} -geometry +200+83 -composite "
   ." {$mainPath}{$icon7} -geometry +7+130 -composite output.jpg";
   
   exec($command);

   ?>
   
   <img src="output.jpg">
I do not like all the { } I would have defined the variables outside the $command and you would not need them.

Re: Adding multiple images to a background image

Posted: 2008-06-14T08:02:32-07:00
by bbunlock
Bonzo thank you very much for the help, it worked perfectly :D

very much appriciated

Re: Adding multiple images to a background image

Posted: 2008-06-14T11:10:56-07:00
by fmw42
why don't you use convert ... -composite syntax in stead of composite? then you can put it all in one command line.

see http://www.imagemagick.org/Usage/layers/#convert

Re: Adding multiple images to a background image

Posted: 2008-06-14T22:04:21-07:00
by anthony
For better still use -flatten, -mosaic, and the ultimate -layers merge. techniques
http://imagemagick.org/Usage/layers/#example

This is designed with multiple image 'layering' in mind!!!! Just what you are wanting.

PS: don't forget to look at the other examples referred to by this one.


PPS: your original example was missing either a newline or a semi-colon (;) to seperate the multiple commands you have in your single 'shell script' call. It is not however a 'single' command, such as the 'layering' technqiues, or other techniques on the layering page.