Changing Hue in a image dynamically using GD

Posted on 2008-11-16
Last Modified: 2012-05-05
Is it possible to change the hue in a image from a location (image/logo.png) and resave to another location?
Question by:Sam Cohen
    LVL 6

    Expert Comment

    Hi there,

    Having had a little look around, I stumbled across this link:

    It looks as if changing the hue in the GD Library is not directly catered for. An alternative suggestion I saw was to use the ImageMagick library:

    Hope that helps,
    LVL 8

    Author Comment

    by:Sam Cohen
    how can i use this with a common image located in the image folder?
    LVL 6

    Accepted Solution

    Ok, the code from that page is shown below.

    As far as my knowledge goes, you'd have to change 2 things on the following line:
    $im = imagecreatefrompng("b2.png") or die ("Cannot Initialize new GD image stream");

    You'd need to change imagecreatefrompng to suit your image format i.e. imagecreatefromjpeg. You'd also need to change the filepath to your image i.e. imagecreatefromjpeg("/images/example.jpg").

    If you want to save it, you need to change the following line:

    and insert a file path like so:

    Hope that helps,
    function make_seed() {
        list($usec, $sec) = explode(' ', microtime());
        return (float) $sec + ((float) $usec * 100000);
    if ($onetwoorthree+1>2)
    //echo " ".$ar[0]." ".$ar[1]." ".$ar[2];
    $im = imagecreatefrompng("b2.png") or die ("Cannot Initialize new GD image stream");
    header ("Content-type: image/jpeg");
    for ($x=0;$x<$width;$x++){
    	for ($y=0;$y<$height;$y++){
    		$rgb = ImageColorAt($im, $x, $y);
    		$r = ($rgb >> 16) & 0xFF;
    		$g = ($rgb >> 8) & 0xFF;
    		$b = $rgb & 0xFF;
    		$color = imagecolorallocate($im2, $r, $g, $b);

    Open in new window

    LVL 8

    Author Comment

    by:Sam Cohen
    One more question. Where would i add the values, inorder to change the color?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now