GD LIB – problem with resulting image size

Hi everyone.
Im having al ittle difulty with the GD lib and wondered if some one could help me out.

I have two images. 1 a jpg and the other a transparent PNG

I wish to firstly, resize the jpg. ( which i am doing successfully ).
I then want to lay the jgp BEHIND the png which basically has a transparent box in the middle which will show the jgp behind.

Im having a problem which is i am lsoing the width and height of the png for some reason or somethime like is hapening.

Firstly , i resize my original image which results in a image size 360×268

Code:

$percent = 0.5;

list($width, $height) = getimagesize('meanddad.jpg');
$new_width = $width * $percent;
$new_height = $height * $percent;
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg('meanddad.jpg');

imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

imagejpeg($image_p, "underlay_image.jpg");


WORKS FINE and underlay_image.jpg is created.

THEN i try to place this image behind a png which is 504 x 405
I want to keep the resulting image and NOt crop or effect the png.

Code:


$width = 540;
$height = 405;
 
$bottom_image = imagecreatefromjpeg('underlay_image.jpg');
$top_image = imagecreatefrompng('Photo-Template.png');

imagesavealpha($top_image, false);      // enable transparancy
imagealphablending($top_image, false);

imagecopy($bottom_image, $top_image, 0, 0, 0, 0, $width, $height);

imagepng($bottom_image, "new_image.png");


The resulting image new_image.png is 360×268 NOT 504×405 and accrodingly, the front image ( the png ) is now cropped.

I am sure i have done something silly would would really aprepciate a pointer on this please.

Thanks

View full post on Tycoon Talk

, , ,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Adobe Flash playerPlugin by wpburn.com wordpress themes


RSS Site FeedRSS Site Feed

© 1992-2011 DC2NET™, Inc. All Rights Reserved