0

Imagine I have 2 pictures, imagea.jpg and imageb.jpg

ImageA

Image A

ImageB

Image B

I want to combine these both pictures un just 1 and output them to a file imageab.jpg, just like here

ImageA ImageB

I will do this running cron jobs, so I need to do that on PHP, but I'm getting troubles with previous codes. As additional information, I'm getting the ImageA/B URLs from MySQL and all pictures have the same width and height.

Thanks!

Zul
  • 3,627
  • 3
  • 21
  • 35
Luis
  • 1,067
  • 1
  • 14
  • 25

3 Answers3

3

You can use imagecopymerge:

Something like this:

$dest = imagecreatefromgjpg('imagea.jpg');
$src = imagecreatefromjpg('imageb.jpg');

// Copy and merge
imagecopymerge($dest, $src, 10, 10, 0, 0, 100, 47, 75);

// Output and free from memory
header('Content-Type: image/jpeg');

imagejpeg($dest);

imagedestroy($dest);
imagedestroy($src);
Zul
  • 3,627
  • 3
  • 21
  • 35
2

Imagick is your friend.

For example Imagick::appendImages.

markus
  • 40,136
  • 23
  • 97
  • 142
  • This is the correct answer, but how can I make it, can you edit with the code? Thanks! – Luis Feb 18 '12 at 15:38
  • 1
    What code would you need, everything you need to know is in the manual? – markus Feb 18 '12 at 15:41
  • Yes, but they are doing images from colors, I want to know how to do the same but with previously done images (image url). Thanks! – Luis Feb 18 '12 at 15:42
  • 1
    Exactly the same but instead you load the images first with Imagick::readImage. – markus Feb 18 '12 at 15:44
1

Take a look at GD and imagemagick, they are plenty of functions that can help you: http://php.net/manual/en/function.imagecopymerge.php

markus
  • 40,136
  • 23
  • 97
  • 142
acanimal
  • 4,800
  • 3
  • 32
  • 41