John Davidson

Getting black screen after merging my images in PHP

0 comments
Message:


image 1
image 2


When I am merging the images I am getting the image like this:merged image


Here is my code:


$topFile = imagecreatefromjpeg($strTopFilePath);
$bottomFile = imagecreatefromjpeg($strBottomFilePath);

list($intTopFileWidth, $intTopFileHeight) = getimagesize($strTopFilePath);
list($intBottomFileWidth, $intBottonFileHeight) = getimagesize($strBottomFilePath);

// compute new width/height
$intNewFileWidth = ($intTopFileWidth > $intBottomFileWidth) ? $intTopFileWidth : $intBottomFileWidth;
$intNewFileHeight = $intTopFileHeight + $intBottonFileHeight;
// create new image and merge

$new = imagecreatetruecolor($intNewFileWidth, $intNewFileHeight);
imagecopy($new, $topFile, 0, 0, 0, 0, $intTopFileWidth, $intTopFileHeight);
imagecopy($new, $bottomFile, 0, $intTopFileHeight+1, 0, 0, $intBottomFileWidth, $intBottonFileHeight);
imagejpeg($new, $strMergedPath);

Please help. Thanks in Advance.



My Answer:
+ $intBottomFileWidth;
$intNewFileHeight = $intTopFileHeight + $intBottomFileHeight;

// create a new image with the new dimensions
$mergedImage = imagecreatetruecolor($intNewFileWidth, $intNewFileHeight);

// merge the top and bottom images onto the new image
imagecopy($mergedImage, $topFile, 0, 0, 0, 0, $intTopFileWidth, $intTopFileHeight);
imagecopy($mergedImage, $bottomFile, 0, $intTopFileHeight, 0, 0, $intBottomFileWidth, $intBottomFileHeight);

// output the merged image
header('Content-Type: image/jpeg');
imagejpeg($mergedImage);

// free up memory
imagedestroy($topFile);
imagedestroy($bottomFile);
imagedestroy($mergedImage);

Rate this post

4 of 5 based on 3908 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us