Jump to content

Answered: PHP Image Help Needed


Teh Unseen

Recommended Posts

Ok, I'm working on a project for a site of mine. I got everything working perfectly so far, but for some reason this TINY little part won't work. <_< I basically create an image from a bunch of other images. I have the user's skin color as green on the images so I can change the color in the PHP script. But the "imagecolorset()" function is not working for me.

Image:
[url=http://rsbattle2.com/files/character/index.php?view_user=1]http://rsbattle2.com/files/character/index.php?view_user=1[/url]

[quote]imagecolorset($user_image, imagecolorexact($user_image, 0, 255, 0), 0, 0, 255);[/quote]
I see nothing wrong with this. It should take the color green (0, 255, 0) and change it to blue (0, 0, 255). Any ideas as to why it is not working?

And no "imagecolorclosest()" does not work either (instead of "imagecolorexact()").

Also, I know "imagecolorset()" works as I have tested it with this script I found:
[quote]header("Content-type: image/png");
$im = imagecreate(200, 200);
$red = imagecolorallocate($im, 255, 0, 0);
$offblue = imagecolorallocate($im, 90, 90, 200);
imagefill($im, 0, 0, $red);
imagefilledrectangle($im, 10, 10, 40, 40, $offblue);
// above could come from an uploaded image
// find a blue in the image
$newblue = imagecolorclosest($im, 0, 0, 255);
// change it to green
imagecolorset($im, $newblue, 0, 255, 0);
imagepng($im);
imagedestroy($im);[/quote]

I can change the green to transparent when I use the code below, it just won't let me change colors. >_<
[quote]imagecolortransparent($user_image, imagecolorexact($user_image, 0, 255, 0));[/quote]
Link to comment
https://forums.phpfreaks.com/topic/26997-answered-php-image-help-needed/
Share on other sites

It not going to work, because the function imagecolorexact(), does not work on the palette colors, it only works on allocated colors, which means the function can only work on images that contain a local palette (256 colors) or less! So you need to convert your images from 16BIT high color to a palette image, imagecreate(); before doing your color change!

[code]<?php

/* ./image.png is the green image, ./new.png is the new blue image */

list ( $w, $h ) = getimagesize ( './image.png' );

$old = imagecreatefrompng ( './image.png' );

$new = imagecreate ( $w, $h );

imagecopy ( $new, $old, 0, 0, 0, 0, $w, $h );

imagecolorset ( $new, imagecolorexact ( $new, 0, 255, 0 ), 0, 0, 255);

imagepng ( $new, './new.png' );

imagedestroy ( $new );

?>[/code]

Sonia

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.