Luis
Luis

Reputation: 1097

Combine 2 or more pictures in PHP

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!

Upvotes: 0

Views: 232

Answers (3)

Zul
Zul

Reputation: 3608

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);

Upvotes: 3

acanimal
acanimal

Reputation: 5020

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

Upvotes: 1

markus
markus

Reputation: 40675

Imagick is your friend.

For example Imagick::appendImages.

Upvotes: 2

Related Questions