Jump to content

Image manipulation - GD libraries - question.


kernelgpf

Recommended Posts

Basically, on my website, you can own dragons. Now, there are MANY MANY colors of dragons. I have a default picture I want to be used, but depending on the color, I want PHP to color the dragon. Basic colors, like red, blue, and yellow, but also complicated things like "cheetah spotted" and "cloudy" and still, the image must be shaded. I can get all of the "skins" drawn, but is there some way [without using absolute positioning in CSS/HTML] to make the skin over-lap the dragon perfectly, where it would appear the default picture covered with the skin was really one picture?

 

Kind of confusing, but please help. Thanks. =]

Link to comment
https://forums.phpfreaks.com/topic/44043-image-manipulation-gd-libraries-question/
Share on other sites

Make it once picture, read the default dragon image into a temporary png file, aswell as the skin - a transparent png file with only the necessary colours and shading non transparent, and then map the png file on top, the same way one would put a watermarked image on a bigger image, except the two would be exactly the same size.

 

Is that the kinda thing you're looking for?

For this code you need a dragon image that is a silhouette on a white background. You also need a gif file to supply the "skin" for the dragon.

 

The code uses the dragon image (dragon.phg) as a stencil.

 

I have attached a couple of sample images to use with the code

 

::page on which dragon appears::

<img src="dragon.php?skin=bluetexture.gif" />

 

::dragon.php::

<?php
$skinfile = $_GET['skin'];

$skin = imagecreatetruecolor(107,130);
$tile = imagecreatefromgif($skinfile);
imagesettile($skin, $tile);
imagefill($skin, 54, 65, IMG_COLOR_TILED);

$dragon = imagecreatefrompng('dragon.png');

$bgd = imagecolorat($dragon,0,0);
$white = imagecolorallocate ($skin, 255,255,255);

for ($x=0; $x<107; $x++) {
    for ($y=0; $y<130; $y++) {
        if (imagecolorat($dragon,$x,$y) == $bgd) {
            imagesetpixel($skin,$x,$y,$white);
        }
    }
}
header("content-type: image/png");
imagepng($skin);
imagedestroy($skin);
imagedestroy($dragon);
imagedestroy($tile);
?>

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.