View Full Version : Layering Two Images

l33t H4X0R
06-01-2011, 04:58 PM
All i need is some PHP + GD Script which takes two image URLS and Two Coordinates. What I want it to do with those is join the two images at those coordinates.
The effect I would like is for it to take the address of an armour and a sword and make the person (armour) hold the sword

06-02-2011, 06:01 PM
Try this:

# background image
$image1 = imagecreatefromjpeg('comp-bg.jpg');
imagealphablending($image1, true);

# image to composite
$image2 = imagecreatefromjpeg('comp-2.jpg');
$width = imageSX($image2);
$height = imageSY($image2);

# position your image, replacing 220, 315, with 0, 0,
# will place your image to the top left corner
imagecopy($image1, $image2, 220, 315, 0, 0, $width, $height);

imagecolorallocate($image1, 255, 255, 255);

# output to browser
header("Content-type: image/jpeg");

# write image to directory
imagejpeg($image1, "composited.jpg");

# free server memory

If you can use ImageMagick by the command line, take a look at this: