I’m working on a PHP site for a company that produces t-shirts. On the inventory display page, they want to move from an image of the design to an image of the design as it would appear on a t-shirt. Makes sense.
I have three blank tshirt images (black.jpg, white.jpg, grey.jpg), and literally thousands of display images (4558.jpg, etc). I’d really rather not manually merge all the possible combinations in Photoshop (black 4558, white 4558, etc) so I’ve been looking into imagecopymerge() in PHP to do this for me.
Here’s what I’m working with so far:
<?php header('Content-type: image/jpeg'); $color = $_GET["color"]. ".jpg"; $design = $_GET["design"]. ".jpg"; // resize the $design file to half size, store it in $overlay $overlay = imagecreatetruecolor(175, 207); $source = imagecreatefromjpeg($design); imagecopyresized($overlay, $source, 0, 0, 0, 0, 175, 207, 350, 415); $shirt = imagecreatefromjpeg($color); imagecopymerge($shirt, $overlay, 85, 70, 0,0, 175, 207, 100); imagejpeg($shirt); imagedestroy($shirt); ?>
Here’s my test shirt file and my test overlay. When I set the last parameter of imagecopymerge() to 100, I get this. When I change it to 50 (if I’m understanding the purpose of that parameter correctly), I get this.
I think you can see what the problem is. I want to make the white background on the overlay transparent against the color of the shirt, without affecting the other colors at all. Any help would be greatly appreciated!