mardi 10 janvier 2017

imagecopymerge gets black background from end of second image

now it is the third day i try to find a working solution. but i can´t figure it out..

I need to copy a portrait image into a landscape image, but from the end of the portrait the background gets black.

first i create the white landscape image, then i create the portrait in the landscape height and merge the files.

here is my code

//create ladscape with white background
$thumb = imagecreatetruecolor($fullwidth,$fullheight);
$white = imagecolorallocate($thumb, 255, 255, 255);
imagefill($thumb, 0, 0, $white);
//create portrait thumb in landscape height
$thumb1 = imagecreatetruecolor($newwidth,$newheight);

//creating thumbs
//create landscape thumb
 imagejpeg($thumb,"thumb.jpg"); 
 $thumb = imagecreatefromjpeg("thumb.jpg"); 
//load source image
 $source = imagecreatefromjpeg($imgfile); 
 //create portrait thumb
 imagejpeg($thumb1,$ordner."thumb1.jpg");
 $thumb1 = imagecreatefromjpeg($ordner."thumb1.jpg");

//copy source into portrait thumb
 imagecopyresized($thumb1, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 

//merge files
 imagecopymerge($thumb,$thumb1, $centerspace, 0, 0, 0,  $fullwidth,$fullheight, 100); 

//save file
imagejpeg($thumb,$filename,100);

//clear thumbs
 ImageDestroy($thumb); 
 ImageDestroy($thumb1); 
 ImageDestroy($source); 

i tried to create the portrait as png with alpha, but it don´t wont to work..

the attached image is the result (the red box only hide the faces)

result

thanks for your help




Aucun commentaire:

Enregistrer un commentaire