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
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?

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.