Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 291155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:03:47+00:00 2026-05-12T06:03:47+00:00

Here’s the current code I am using. <? header(Content-type: image/png); // example: <img src=gradient.php?height=600&width=100&start=00FF00&end=ff0000

  • 0

Here’s the current code I am using.

<? header("Content-type: image/png");
// example: <img src="gradient.php?height=600&width=100&start=00FF00&end=ff0000" />
$height=100;
$width=1;
$start='000000';
$end='FFFFFF';
extract($_REQUEST); // overwrite using vars from url
$start_r = hexdec(substr($start,0,2));
$start_g = hexdec(substr($start,2,2));
$start_b = hexdec(substr($start,4,2));
$end_r = hexdec(substr($end,0,2));
$end_g = hexdec(substr($end,2,2));
$end_b = hexdec(substr($end,4,2));
$image = @imagecreate($width,$height);
for($y=0;$y<$height;$y++){
    for($x=0;$x<$width;$x++){
        if($start_r==$end_r) $new_r = $start_r;

        $difference = $start_r-$end_r;
        $new_r = $start_r-intval(($difference/$height)*$y); 

        if($start_g==$end_g) $new_g = $start_g;

        $difference = $start_g-$end_g;
        $new_g = $start_g-intval(($difference/$height)*$y);     

        if($start_b==$end_b) $new_b = $start_b;

        $difference = $start_b - $end_b;
        $new_b = $start_b-intval(($difference/$height)*$y);

        $row_color = imagecolorresolve($image,$new_r,$new_g,$new_b);
        imagesetpixel($image,$x,$y,$row_color);
    }    
}
imagepng($image);
imagedestroy($image);
?>

The above code works perfect in making vertical (top to bottom) gradients but I’d like to be able to make horizontal ones as well. I have a very good understanding for PHP, but I don’t deal with PHP image functions very often. If someone can help me and figure this out I’d really appreciate it!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:03:48+00:00Added an answer on May 12, 2026 at 6:03 am

    This code will work for vertical gradient and make it faster as well.

    I have commented out useless code so you know what to delete.

    for($x=0;$x<$width;$x++){
        /*if($start_r==$end_r) $new_r = $start_r;*/
        // ^^ the line above is useless, $new_r will be set below either way
    
        $difference = $start_r-$end_r;
        $new_r = $start_r-intval(($difference/$width)*$x); 
    
        /*if($start_g==$end_g) $new_g = $start_g;*/
        // ^^ the line above is useless, $new_g will be set below either way
    
        $difference = $start_g-$end_g;
        $new_g = $start_g-intval(($difference/$width)*$x);     
    
        /*if($start_b==$end_b) $new_b = $start_b;*/
        // ^^ the line above is useless, $new_b will be set below either way
    
        $difference = $start_b - $end_b;
        $new_b = $start_b-intval(($difference/$width)*$x);
    
        $new_color = imagecolorresolve($image,$new_r,$new_g,$new_b);
        // ^^ used to be $row_color
    
        for($y=0;$y<$height;$y++){
            imagesetpixel($image,$x,$y,$new_color);
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 169k
  • Answers 169k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Because it's putting things in the code that no one… May 12, 2026 at 2:00 pm
  • Editorial Team
    Editorial Team added an answer Yes, it is possible, via the C backend, but it… May 12, 2026 at 2:00 pm
  • Editorial Team
    Editorial Team added an answer Well, the UI thread is likely to have a higher… May 12, 2026 at 2:00 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.