What is wrong with my php code?

william

New member
What is wrong with my php code
it is supposed to get a hex color code and replace the image's transparency with the hex color.
The image will be a chosen from another get request from the list of images, 1,2,on and on.
Please help i am not great with php.

<?php

function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){
$opacity=$pct;
// getting the watermark width
$w = imagesx($src_im);
// getting the watermark height
$h = imagesy($src_im);

// creating a cut resource
$cut = imagecreatetruecolor($src_w, $src_h);
// copying that section of the background to the cut
imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
// inverting the opacity
$opacity = 100 - $opacity;

// placing the watermark now
imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
imagecopymerge($dst_im, $cut, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $opacity);
}

$images = array(
// add the list of images here
1 => 'image.png',
2 => 'helloworld.png',
);

# Get the image that should be loaded
$s = $_GET['s'];

# Load the image itself
$image = imagecreatefrompng($images[$s]);

# Add transparent background
imagesavealpha($image, true);
imagealphablending($image, false);

# Get the color and convert it to an integer
$c = hexdec($_GET['c]);

# Get the image of the plain color
$color = imagecreatetruecolor(imagesx($image), imagesy($image));
imagefilledrectangle($color, 0, 0, imagesx($color), imagesy($color), $c);

# Copy the original image on top of the color image
imagecopymerge_alpha($color, $image, 0, 0, 0, 0, imagesx($color), imagesy($color), 100);

# Destroy $image and replace it with $color
imagedestroy($image);
$image = $color;
unset($color);
php>
 
Back
Top