2

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.

I attach here an example of what I get: enter image description here

Community
  • 1
  • 1
Sarah
  • 325
  • 6
  • 17
  • 1
    exactly HOW is this not working? – Marc B Jan 15 '16 at 15:50
  • @Marc: Only half of the images get displayed and a big black gap appears in between. See attached example – Sarah Jan 15 '16 at 16:07
  • what attached example? – Marc B Jan 15 '16 at 16:08
  • @Marc: The image I have attached. – Sarah Jan 18 '16 at 10:07
  • you rotated your images 270 degrees, but use the ORIGINAL image to get your height/width. since you rotated 270 degrees, that means the height of the original image is now the WIDTH of the rotate image. so you are copying properly, just using height/width in the opposite sense. – Marc B Jan 18 '16 at 14:47

0 Answers0