We have over 500 different combinations of an image. The idea is to overlay two layers over a JPG and serve it to the user as a single image. We are trying to use the GET to select the different variations of the image. A live example of this script in action is this: https://signaturecustomwoodworking.com/sys/img/cabinets/preview.php?oe=4&ie=10 but it doesn’t seem to be working. I have already confirmed that the images at the directories are there too.
<?php
if ($_GET) {
$bg = isset($_GET['bg']) ? 'oe/' . $_GET['oe'].'jpg' : false;
$fg = isset($_GET['fg']) ? 'ie/' . $_GET['ie'].'png' : false;
if (file_exists($bg) && file_exists($fg)) {
// Create image instances
$dest = imagecreatefromjpeg($bg);
$src = imagecreatefrompng($fg);
$wd=imageSX($dest);
$ht=imageSY($src);
// Copy and merge
imagecopymerge_alpha($dest, $src, 0, 0, 0, 0, $wd, $ht,100);
// Output and free from memory
header('Content-Type: image/gif');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
}
}
function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){
// creating a cut resource
$cut = imagecreatetruecolor($src_w, $src_h);
// copying relevant section from background to the cut resource
imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
// copying relevant section from watermark to the cut resource
imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
// insert cut resource to destination image
imagecopymerge($dst_im, $cut, $dst_x, $dst_y, 0, 0, $src_w, $src_h, $pct);
}
?>