Page 1 of 1

Adjusting images in php

Posted: Fri Jul 01, 2011 3:11 am
by Wizard32
Hi all

I was searching throw the Imagic and GD libary but couldnot find a function near info on google about this question.

I want to adjust the total count of colors in an image but how to do that?
I couldnot find a function 'setColorCount' or what so ever

Thanks a lot

Re: Adjusting images in php

Posted: Fri Jul 01, 2011 5:43 am
by Apollo
Out of curiosity, why would you want to do this? :) There's the option to save an image as gif (paletted, i.e. 256 colors) or truecolor (png/jpg/etc), but what's the point of explicitly adjusting the color count in an image?

(I can imagine some purposes for this, but not in a web/php related context)

Re: Adjusting images in php

Posted: Fri Jul 01, 2011 6:05 am
by Wizard32
My mom wants to embroidery pictures but she only has x amount of colors (else it gets to dificult for her)
So i want to make her a tool that she can upload pictures, adjust the count of colors and then print the image with color mapping so she can embroidery w/e she wants :)

Re: Adjusting images in php

Posted: Fri Jul 01, 2011 10:05 am
by Apollo
Haha, that's cool man :)

Well what you're looking for is essentially a color quantization algorithm. I dunno if there are any PHP libraries available that do this for you, but if your hosting server has imageMagick installed (most servers do), you can do it by executing a shell command like this:

Code: Select all

convert mommy.jpg -colors 5 mommy.png
This will reduce mommy.jpg to only 5 unique colors and save the result as mommy.png.

Re: Adjusting images in php

Posted: Fri Jul 01, 2011 10:08 am
by Wizard32
I will try it out and let you know here if it worked

Thanks a lot ;)

Re: Adjusting images in php

Posted: Mon Jul 04, 2011 5:44 am
by Wizard32
I did some testing and it works good so thanks a lot Apollo