image merging
Posted: Tue Jul 25, 2006 2:42 am
hi,
i have the following problem: I've got a picture, a jpg photo with variabel size. What i want to do is put the jpg over a new image (this one is bigger) and save it to a png.
The reason for this is because i need to create images with the same width & height but a user can upload the photos so they have different width & height. Like this: user uploads photo -> create new transparent image -> put photo over it -> save the image to png
Result is a photo (bigger then the original) with a transparent background.
My problem lies here: when i use imagecreate for the new image the transparency is ok, but the colors of my photo are wierd. Then i used imagecreatetruecolor but then the transparency was lost (i got a black square with my photo over it)
a bit of code to verify
thanks in advance
ps: sorry for the language errors
i have the following problem: I've got a picture, a jpg photo with variabel size. What i want to do is put the jpg over a new image (this one is bigger) and save it to a png.
The reason for this is because i need to create images with the same width & height but a user can upload the photos so they have different width & height. Like this: user uploads photo -> create new transparent image -> put photo over it -> save the image to png
Result is a photo (bigger then the original) with a transparent background.
My problem lies here: when i use imagecreate for the new image the transparency is ok, but the colors of my photo are wierd. Then i used imagecreatetruecolor but then the transparency was lost (i got a black square with my photo over it)
a bit of code to verify
Code: Select all
<?php
//create the new image
$image = imagecreate(600,600);
//set the color to white
$back = imagecolorallocate($image, 255, 255, 255);
//make white transparent
imagecolortransparent($image,$col);
//create an image from the photo
$photo = imagecreatefromjpeg("test.jpg");
//copy the two together
imagecopymerge($image,$photo,50,50,0,0,400,500,75);
//output a correct header
header('Content-type: image/png');
// and finally, output the result
imagepng($image);
imagedestroy($image);
imagedestroy($foto);
?>ps: sorry for the language errors