Click to See Complete Forum and Search --> : edit colours of existing image- how?
mitya
10-15-2003, 11:57 AM
I'm having a little trouble finding out how to edit the colours of an existing image and output it through php. For example, if I tell it to read an image in a folder but change X colour, how would that be done? The only ways I've discovered so far involve images made there and then, on-the-fly, not existing files.
Can anyone point me in the right direction?
Cheers.
PunkSktBrdr01
10-15-2003, 08:24 PM
I've never done anything like this, but if you are using a palette-based image, try imagecolorset() (http://us4.php.net/manual/en/function.imagecolorset.php).
mitya
10-16-2003, 07:23 AM
THanks for that but I still don't know how to actually apply this to an existing image. How do you return the image and show its results afterwards?
I can't seem to crack this, despite extensive research.
Thanks
PunkSktBrdr01
10-16-2003, 04:56 PM
Wouldn't returning the image show the results? Anyway, read the documentation for imagecolorset().
mitya
10-16-2003, 05:47 PM
Nah returning it shows nothing, and if I try to display the image of <img src="<?php echo $im_object; ?>"> I get a failed image because it's looking for an image called 'resource locator #1.gif'.
When you first specify $im_object, do I simply say...
$image = "imgs/logo.gif";
or the whole caboodle, ala...
$file = "imgs/logo.gif";
$pointer = fopen($file, "r");
$image_to_feed_to_function = fread($pointer, filesize($file));
I'll have a *second* read of the bit you mentioned.
p.s. I've tried it with other image formats too.
PunkSktBrdr01
10-16-2003, 06:05 PM
I'm kinda confused... Post the code.
mitya
10-17-2003, 03:14 AM
Umm I can't really post anything other than what I did. Perhaps I should just re-word it better.
Basically, the above post by me was showing the different ways I've tried to OPEN an EXISTING image and then feed it to an image-treating function which changes colours.
You have to specify an object, right? Such as:
$image_object = imagecreatefrompng($image, etc...
But to feed it $image, do you open it with:
$image = "imgs/logo.gif";
...or the other way, i.e. using a $file, $handle and fread etc?
Hope this makes sense- thanks for perseverance.
You're outputting the image wrong. Take a look at this. This will take the image foo.gif, change all the black to red, and output it as a png.
<?php
header("Content-type: image/png");
$im = imagecreatefromgif("foo.gif");
imagecolorset ($im, 0, 255, 0, 0);
imagepng ($im);
imagedestroy ($im);
?>
mitya
10-17-2003, 08:32 AM
Now I'm starting to really dislike you, Pyro, this is the umteenth time you've pissed all over my problems and effortlessly solved it!
Thanks mate.
lol... :D
No problem, buddy...