andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Saturation

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Image Functions
View previous topic :: View next topic  
Author Message
stuffedcat
Newbie


Joined: 05 Jul 2005
Posts: 1

PostPosted: Tue Jul 05, 2005 8:07 am    Post subject: Saturation Reply with quote

Hi,

I came across your script via zend.net - where it said "This library makes it really easy to change the hue, saturation, brightness, and colour of an image"

Sorry for being stupid, but I can't work out how you change the hue, saturation or brightness of an image with the script!

You see, I have a whole bunch of images that I would like to change the saturation (down by about 60%), brightness (down by about 5%) and colour of and I was hoping this script would allow me to do it. I've worked out how to change the colour of the image, but not the saturation or brightness.

Could you help?
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Tue Jul 05, 2005 11:14 am    Post subject: Reply with quote

Hi, and welcome to the board!

Okay, so 'really' easy is a bit of an over-statement, because I've really just neglected to put in a function to tweak the saturation. But with the other functions that are there, it's possible 'fairly' easily tweak the saturation. Smile

What you want to do is copy the colourise function, but instead of altering the hue you want to alter the saturation. Something like:

PHP:
<?php function saturation(&$im$level)
    {
        
$sx imagesx($im);
        
$sy imagesy($im);
        for (
$x 0$x $sx$x++) {
            for (
$y 0$y $sy$y++) {
                
$rgb Image::getPixelRGB($im$x$y);
                
$pxhls Image::rgb2hls($rgb);
                
$pxhls[2] = /* calculation with your */ $level;
                
$rgb Image::hls2rgb($pxhls);
                
imagesetpixel($im$x$yimagecolorallocate($im$rgb[0], $rgb[1], $rgb[2]));
            }
        } 
    } 
?>


So you'd modify that to either take your level as a literal value, or work out the percentage, etc. Remember that the saturation level is expected to be a number between 0 and 1.

Make sense?

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Image Functions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group