Jump to content

Image Creation [PNG]


javier

Recommended Posts

Hello, I've been working with a script to display certain information from my game's characters over a png rectangle, something like this:

|Info here|

The thing is, I'd like to color it with a vertical gradient, but I haven't been able to do so.
I got this code off some webiste (might be outdated..?):

[code]
function imagecolorgradient($img, $hv, $x1, $y1, $x2, $y2, $f_c, $s_c)
{
  // Modified version of code by info@solanki.ch taken from php.net
  // posted: 14-Feb-2004 07:43

  // $img is the image handle.
  // $hv is either horizontal 'h' or vertical 'v' gradient.
  // $x1 and $y1 are the start points.
  // $x2 and $y2 the ending points.
  // $f_c and $s_c are the first and second color ARRAYs.

  if ($hv == 'v')
  {
    $y = ($y2 > $y1) ? $y2-$y1 : $y1-$y2;
  }
  else
  {
    $x = ($x2 > $x1) ? $x2-$x1 : $x1-$x2;    
  }
    
  $r_range = ($f_c[0] > $s_c[0]) ? $f_c[0] - $s_c[0] : $s_c[0] - $f_c[0];
  $g_range = ($f_c[1] > $s_c[1]) ? $f_c[1] - $s_c[1] : $s_c[1] - $f_c[1];
  $b_range = ($f_c[2] > $s_c[2]) ? $f_c[2] - $s_c[2] : $s_c[2] - $f_c[2];

  if ($hv == 'v')
  {
    $r_px=$r_range/$y;
    $g_px=$g_range/$y;
    $b_px=$b_range/$y;
    $xy = $y;
  }
  else
  {
    $r_px=$r_range/$x;
    $g_px=$g_range/$x;
    $b_px=$b_range/$x;
    $xy = $x;
  }
    
  $r=$f_c[0];
  $g=$f_c[1];
  $b=$f_c[2];

  
  for($i=0;$i<=$xy;$i++)
  {
    $col=imagecolorallocate($img,round($r),round($g),round($b));
    if ($hv == 'v')
    {
      imageline($img,$x1,$y1+$i,$x2,$y1+$i,$col);
    }
    else
    {
      imageline($img,$x1+$i,$y1,$x1+$i,$y2,$col);
    }
    
    $r = ($f_c[0] < $s_c[0]) ? $r + $r_px : $r - $r_px;
    $g = ($f_c[1] < $s_c[1]) ? $g + $g_px : $g - $g_px;
    $b = ($f_c[2] < $s_c[2]) ? $b + $b_px : $b - $b_px;
  }
  return $img;
}
[/code]

The thing is, I don't know how to create the gradient off that code. I tried the following:

[code]
imagecolorgradient($myImage, 1, 20, ($iWidth-2), ($iHeight-2), $dkblue, $blue);

// where
$myImage = imagecreate($iWidth, $iHeight);

//and $blue, $dk blue are rgb colors
[/code]

That's about it.
Any help would be appreciated.
Link to comment
Share on other sites

Might look here...

[a href=\"http://www.poirrier.be/~jean-etienne/info/clibs/gd-rainbow.php\" target=\"_blank\"]http://www.poirrier.be/~jean-etienne/info/.../gd-rainbow.php[/a]

or

[a href=\"http://frenchfragfactory.net/ozh/my-projects/images-php-gd-gradient-fill/\" target=\"_blank\"]http://frenchfragfactory.net/ozh/my-projec...-gradient-fill/[/a]

or

[a href=\"http://www.php-editors.com/contest/1/68-read.html\" target=\"_blank\"]http://www.php-editors.com/contest/1/68-read.html[/a]

Lite...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.