View Single Post
  #3  
Old 10-16-2012, 03:17 PM
PTGigi's Avatar
PTGigi PTGigi is offline
Crazily Friendly~HoF
 
Join Date: Jul 2009
Location: Somewhere >.>
Posts: 370
Gender: Female
Credits: 26,299
PTGigi
Default

Recoloring an image is pretty easy, just kinda annoying to do. I'll be using GIFs as an example, because this method changes color by individual pixels, and PNGs can have lots of colors while GIFs generally have a more defined palette.

For this, we use the function imagecolorset as well as imagecolorexact. imagecolorset changes the defined color to a new one, while imagecolorexact picks the exact color we want to change. There are other functions to grab colors as well, but I find imagecolorexact to be the more flexible (there is also imagecolorclosest, which I've never tried to use and just discovered while typing up this tutorial. Sounds nicer though (grabs a color close to the one you selected if the one you selected doesn't exist), so I almost suggest using that XD). There's also imagecolorat which just defines it based on the specified pixel (x,y). It's very inflexible, so I don't really suggest using it.
PHP Code:
 <?php
 header
('Content-Type: image/gif');
 
$img imagecreatefromgif('imageurl');
  
 
$changecolor=imagecolorexact($img,255,255,255);
 
imagecolorset($img$changecolor255255255);
  
 
imagegif($img);
 
imagedestroy($img);
 
?>
Changing colors relies on RGB color values. If you don't know RGB very well, I'd suggest looking for a color picker that shows RGB values or a looking for a hex to RGB code snippet for PHP. I prefer the latter ;D

imagecolorexact(IMAGE,RED,GREEN,BLUE);
IMAGE is your image. This is so it can get the color palette from your image
RED the red value of the color (value between 0-255)
GREEN the green value of the color (value between 0-255)
BLUE the blue value of the color (value between 0-255)

DERP. I DECIDED TO START WRITING THIS IN THE MIDDLE OF CLASS. But now I have work to do sooooooo this will be left half finished until I get around to it. Sorry XD
__________________


"I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo
My Adoptables|Nuzlocke Webcomic

Last edited by PTGigi; 10-19-2012 at 09:46 AM.
Reply With Quote