GD Lib - how merge 2 images into 1?
Posted: Thu Nov 12, 2009 7:42 am
Hehh, long time no posting! In fact long time no programming at all. And after like 5 minutes I start programming again I bump into a problem I can't solve.
Here it is:
I am trying to create a simple script that would take 2 images and merge the 2. They are a jpg image (the background) and a png image with alpha transparency as the foreground. Imagine it like layers of images in photoshop. I'd like to place the foreground on top the the background. I can either display the foreground or the background but can't display the foreground on top of the background.
Here is the code I've got so far:
Thanx in advance
Here it is:
I am trying to create a simple script that would take 2 images and merge the 2. They are a jpg image (the background) and a png image with alpha transparency as the foreground. Imagine it like layers of images in photoshop. I'd like to place the foreground on top the the background. I can either display the foreground or the background but can't display the foreground on top of the background.
Here is the code I've got so far:
Code: Select all
$base_dst = imagecreatetruecolor(47, 47);
imagealphablending($base_dst, false);
imagesavealpha($base_dst, true);
$base = imagecreatefromjpeg('images/icon_base.jpg');
imagecopyresampled($base_dst, $base, 0, 0, 0, 0, 47, 47, 47, 47);
$icon_dst = imagecreatetruecolor(47, 47);
imagealphablending($icon_dst, false);
imagesavealpha($icon_dst, true);
$icon = imagecreatefrompng('images/icons/64_64/icon01_13.png');
imagecopyresampled($icon_dst, $icon, 0, 0, 0, 0, 47, 47, 64, 64);
header('Content-Type: image/png');
imagepng($base_dst);