1

I am adding a line of text onto an image. Is it possible to overlay multiple lines (line2.png & line3.png) onto the same image?

$stamp = imagecreatefrompng('img/line1.png');
$im = imagecreatefromjpeg('tom.jpg');

// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 40;
$sx = imagesx($stamp);
$sy = imagesy($stamp);

// Copy the stamp image onto our photo using the margin offsets and the photo 
// width to calculate positioning of the stamp. 
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));

// Output and free memory
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
miken32
  • 42,008
  • 16
  • 111
  • 154
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192

1 Answers1

0

Yes, you can by using imagecopy.

Typical usage:

$copyimage = imagecreatefromjpeg("path/to/image/you/want/to/put/into/an/image.jpg");
//$copyimage just needs to be a GD object, so you can also use imagecreatefrompng etc.
imagecopy($image, $copyimage, $position_x, 
            $position_y, 0, 0, $image_width, $image_height);

http://php.net/imagecopy

Charlotte Dunois
  • 4,638
  • 2
  • 20
  • 39