I am trying to display one image at the bottom of another one. In order to achieve this, I have used the method explained in the following link:
Adding one image at the bottom of another in PHP which I have found very useful. However in my case, I am not getting the expected results as I also need to use the imagerotate
property.
My code is the following:
$top_file='photo1.png';
$bottom_file='photo2.png';
$degrees=270;
$top = imagecreatefrompng($top_file);
$bottom = imagecreatefrompng($bottom_file);
// Rotates the images
$rotatetop = imagerotate($top, $degrees, 0);
$rotatebottom = imagerotate($bottom, $degrees, 0);
// get current width/height
list($top_width, $top_height) = getimagesize($top_file);
list($bottom_width, $bottom_height) = getimagesize($bottom_file);
// compute new width/height
$new_width = ($top_width > $bottom_width) ? $top_width : $bottom_width;
$new_height = $top_height + $bottom_height;
// create new image and merge
$new = imagecreate($new_height, $new_width);
imagecopy($new, $rotatetop, 0, 0, 0, 0, $top_width, $top_height);
imagecopy($new, $rotatebottom, 0, $top_height+1, 0, 0, $bottom_width, $bottom_height);
// save to file and display on the browser
imagepng($new,'merged_image.png');
echo '<img src="merged_image.png" alt="Not available" />';
I have tried changing the properties from the imagecopy
function but I cannot find the right way.
I would be grateful if somebody could help me choosing the right settings.