Tizag.com Webmaster Tutorials - A collection of webmaster tutorials from HTML to PHP.

Thursday, December 3, 2009

Overlaping Images of Different Size in PHP using GD Library

Overlaping 2 Images of different size in PHP with Alpha Effect





<?php
//Create new images
$outputImage = imagecreatefromjpeg('page_023.jpg');
$overlapImage = imagecreatefrompng('previewleft_new1.png');


//Grap width and height of Actual Image
$outputImageX = imagesx($outputImage);
$OutputImageY = imagesy($outputImage);

//Grab width and height of the Overlap image
$overlapImageX = imagesx($overlapImage);
$overlapImageY = imagesy($overlapImage);

// Difference in width
$imageWidthDifference = $outputImageX - $overlapImageX;

// Saving Location
$save = 'php-pics/newImage.png';

//Merge the two images
//imagecopymerge($outputImage,$overlapImage,156,50,0,0,$overlapImageX,$overlapImageY,100);
if($overlapImageY < $OutputImageY){
imagecopymerge($outputImage,$overlapImage, $imageWidthDifference,0,0,$OutputImageY,$overlapImageX,$OutputImageY,20);
}else{
imagecopymerge($outputImage,$overlapImage, $imageWidthDifference,0,0,0,$overlapImageX,$OutputImageY,20);
}
//Output header
header('Content-type: image/png');
//send new image to browser
imagepng($outputImage, $save);
//imagedestroy($outputImage);

?>

No comments: