JoeBuck69 Posted May 7, 2009 Share Posted May 7, 2009 I have been struggling with the following task: Here is my original image: Here is an image with only 15 colors: I want to take the original image and change the colors in it to ONLY use the colors that exist in the 15 color image. Is there a php function or procedure that you know of that will lead me in the right direction? Link to comment https://forums.phpfreaks.com/topic/157266-change-colors-of-image-to-specific-palette/ Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Hmm, never looked into that before, but try looking through the GD package - http://us2.php.net/manual/en/book.image.php Link to comment https://forums.phpfreaks.com/topic/157266-change-colors-of-image-to-specific-palette/#findComment-828805 Share on other sites More sharing options...
JoeBuck69 Posted May 7, 2009 Author Share Posted May 7, 2009 try looking through the GD package I am using the GD functions. I've successfully cropped my image, resized it to the size I want, but now need to convert it based on the palette. I'm wondering if I'll need to loop through each pixel in the original image and compare it to each of the 15 colors of the palette image and choose the "closest" one to replace the original pixel with? Link to comment https://forums.phpfreaks.com/topic/157266-change-colors-of-image-to-specific-palette/#findComment-828813 Share on other sites More sharing options...
Axeia Posted May 7, 2009 Share Posted May 7, 2009 You could loop trough the height/width of the image using gd to grab the color of the pixel, and then compare it to 15 color pallete to look which is the closest. Probably easiest to do with RGB values as those are (at least in my opinion) the easiest to work with. If you're up for a challenge and got imagick available (the challenge is that the documentation is reallly poor) there's a nice example of doing the opposite (extracting a pallete from an image) on http://valokuva.org/?p=72 Link to comment https://forums.phpfreaks.com/topic/157266-change-colors-of-image-to-specific-palette/#findComment-828819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.