Page 1 of 1

Image Composition (Name Consistency)

Posted: 2007-06-24T18:31:02-07:00
by northwest
How do you write the composited images as the same filename as the original images?

I got to compositing multiple images on to canvas, but the final images' filename are inconsistent with the original images' filename.

Code: Select all

<?php

// Get the image
$mgk_wnd1 = NewMagickWand();
MagickReadImages($mgk_wnd1, $img_name = glob("*.jpg"));

// Get number of images stored in the wand
$num_img = MagickGetNumberImages($mgk_wnd1);

// Create a white 640x480 jpeg canvas
$mgk_wnd2 = NewMagickWand();
MagickNewImage($mgk_wnd2, 640, 480, "white");
MagickSetformat($mgk_wnd2, "jpg");

// Set offsets x and y
$x_offset = 150;
$y_offset = 100;

for ($i = 0; $i < $num_img; $i++) {

	if (MagickGetImageHeight($mgk_wnd1) != 480 && MagickGetImageWidth($mgk_wnd1) != 640) {
		
		echo $img_name[$i] . "<br/>";
		// Composite both original image and the canvas
		MagickCompositeImage($mgk_wnd2, $mgk_wnd1, MW_OverCompositeOp, $x_offset, $y_offset);
		
		// Write the image to a file
		MagickWriteImages($mgk_wnd2, "images/$img_name[$i]", TRUE);
		MagickRemoveImage($mgk_wnd1);
		
	}
	
}

// Enhance image
//MagickEnhanceImage($mgk_wnd2);

// Clean up wands
if($mgk_wnd1 && $mgk_wnd2) {
	$mgk_wnd1 = DestroyMagickWand($mgk_wnd1);
	$mgk_wnd2 = DestroyMagickWand($mgk_wnd2);
}

?>


Re: Image Composition (Name Consistency)

Posted: 2007-06-26T18:20:40-07:00
by anthony
Only the background or destination image of a image composition will retain the image meta-data. There are of course minor exceptions, -flatten for example retains the file name of the first image in the image sequence, even though it generates a 'background canvas' as the destination.