--- kihmera_morgain <[EMAIL PROTECTED]> wrote:
> Thanks for the help guys.. turns out i do have a version of GD in my
> php (THANK GOD) (version 2.0.2.8)and seem to have found a script
> pre-made that will do what i want it to (take my semi-transparent 1
> color image and change it to another color), except im having a
> problem having it output the image... using imagepng() i can get the
> image to show in the browser, but i want to get this created image to
> where i can pull it up in a variable on the actual html page. I tried
> the instructions for writing the image to a file and then calling it
> up, but no matter what i tried i always got a pretty vague "The image
> (instertimagenamehere) cannot be displayed because it contains errors"
> when i tried to run the page lol.. i have no luck. Can anyone give me
> simple instructions on how i can take the output from a generic called
> up imagecreatefrompng() script and put it in some semblence of a
> useable form? With it just outputting to browser, it does me no good :x
>
> the example codes on php.net that i saw were way over my head
> (obviously ive been hugging my php for dummies lately)
>
> this is the script ive been using:
> -----------------------------------------------------------
> $image = imagecreatefrompng("myimage.png");
> $width = imagesx($image);
> $height = imagesy($image);
> $colorToChange = "b43b44";
> $newColor = "f0f0f0";
> $c1 = sscanf($colorToChange,"%2x%2x%2x");
> $c2 = sscanf($newColor,"%2x%2x%2x");
> $cnew = imagecolorallocate($image,$c2[0],$c2[1],$c2[2]);
> for ($y=0;$y<$height;$y++) {
> for ($x=0;$x<$width;$x++) {
> $rgb = imagecolorat($image,$x,$y);
> $r = ($rgb >> 16) & 0xFF;
> $g = ($rgb >> 8) & 0xFF;
> $b = $rgb & 0xFF;
> if (($r==$c1[0]) && ($g==$c1[1]) &&
> ($b==$c1[2])) {
> imagesetpixel($image,$x,$y,$cnew);
> }
> }
> }
> header("Content-Type: image/png");
> imagepng($image);
Make sure that your opening PHP tag starts on the first character of the first
line. There should not be any characters after the closing PHP tag.
Also, it is often helpful to include \r\n\r\n after the MIME type (image/png).
James