Adjusting images in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wizard32
Forum Newbie
Posts: 4
Joined: Fri Jul 01, 2011 3:07 am

Adjusting images in php

Post 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
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Adjusting images in php

Post 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)
Wizard32
Forum Newbie
Posts: 4
Joined: Fri Jul 01, 2011 3:07 am

Re: Adjusting images in php

Post 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 :)
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Adjusting images in php

Post 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.
Wizard32
Forum Newbie
Posts: 4
Joined: Fri Jul 01, 2011 3:07 am

Re: Adjusting images in php

Post by Wizard32 »

I will try it out and let you know here if it worked

Thanks a lot ;)
Wizard32
Forum Newbie
Posts: 4
Joined: Fri Jul 01, 2011 3:07 am

Re: Adjusting images in php

Post by Wizard32 »

I did some testing and it works good so thanks a lot Apollo
Post Reply