Would it be remotely possible to, using GD library and PHP, parse a given image and find a specified color and replace it with an image texture? I know how to replace it with another color, but a texture I don't. I couldn't find the solution anywhere :/ Please help?
1st, remotely ? I'd download the image first and then work with it. 2nd, if GD can't do it, maybe you can read the docs of ImageMagick
I don't know how well this would work, but it should produce something close. I'd start by creating a new image the size of the image to be worked on, and using imagecopy to tile in the texture. Then I would use imagecolortransparent and imagecopymerge to set the desired color to transparent in the source image and copy the source image over the newly created texture tiled image.
Joebert: I tried what you said but unfortunately i am getting a problem with the transparency. <?php $tile = $_GET['img']; header( "Content-type: image/png" ); $src = imagecreatefrompng("tile1.png"); $color = imagecolorclosest($src, 0, 148, 255); imagecolortransparent($src, $color); $new = imagecreatetruecolor(50, 50); imagealphablending($src, true); imagesavealpha($src, true); imagecopy($new, $src, 0,0,0,0,50,50); $texture = imagecreatefrompng("_volanic_real.png"); imagecopymerge($new, $texture, 0, 0, 0, 0, 50, 50, 0); $color = imagecolorclosest($src, 0, 148, 255); imagecolortransparent($src, $color); imagepng( $new ); imagedestroy($new); ?> PHP: This just prints the image that I am trying to replace with a texture, but instead of the transparent part---I just get black. Help would be appreciated.
I think you had too much transparency stuff going on. This worked out for me. <?php $src = imagecreatefrompng('pacman.png'); $color = imagecolorclosest($src, 27, 26, 55); imagecolortransparent($src, $color); imagealphablending($src, true); imagesavealpha($src, true); $texture = imagecreatefrompng('pattern.png'); $new = imagecreatetruecolor(460, 460); imagecopy($new, $texture, 0, 0, 0, 0, 460, 460); imagecopymerge($new, $src, 0, 0, 0, 0, 460, 460, 100); imagepng($new, 'test.png'); imagedestroy($new); imagedestroy($src); imagedestroy($texture); ?> PHP: