I am using PHP GD library to create an image over on mockup image first i take mockup image and created a canvas in the center with a width of 250 and a height of 300 and i insert an image in that canvas, it is working fine when a big image comes in because it covers all of the canvas space but problem comes in when a small image comes in like less than canvas size like width of 210 and height of 280 so because it is less than a canvas size it leaves a black space around the image. and also i don't want to reduce canvas size because it is a fixed size. i just want this black color to be transparent.
this is my code:
define("WIDTH", 600);
define("HEIGHT", 600);
$dest_image = imagecreatetruecolor(WIDTH, HEIGHT);
$trans_background = imagecolorallocate($dest_image, 255, 255, 255);
imagecolortransparent($dest_image, $trans_background);
imagefill($dest_image, 0, 0, $trans_background);
$design_image = 'captain.png';
$mockup_image = 't-shirt.png';
$a = imagecreatefrompng($design_image);
$b = imagecreatefrompng($mockup_image);
$pos_left = -19.75;
$pos_top = 37.075;
imagecopy($dest_image, $a, 168, 155, $pos_left, $pos_top, 250, 300);
imagecopy($dest_image, $b, 0, 0, 0, 0, WIDTH, HEIGHT);
imagepng($dest_image, 'final_image.jpg');