Jump to content

Working with images


cheechm

Recommended Posts

I've got some code that basically draws a wavefrom line by line (going horizontally). I was hoping to be able to get a vertical gradient, however I'm not too sure where to start.

 

            imageline(
             $img,
             // x1
             (int) ($data_point / DETAIL),
             // y1: height of the image minus $v as a percentage of the height for the wave amplitude
            $height * $wav - $v,
                          // x2
             (int) ($data_point / DETAIL),
             // y2: same as y1, but from the bottom of the image
             $height * $wav - ($height - $v),
             imagecolorallocate($img, $r, $g, $B)
           );         

 

The full code is available here:

 

Github

 

Another question I have: Is it possible to fill every part of the PNG image which isn't transparent with a solid colour?

 

Thanks

Link to comment
Share on other sites

Do you have a question?

 

Another question I have: Is it possible to fill every part of the PNG image which isn't transparent with a solid colour?

 

Admittedly my first question wasn't as clear. How might I go around drawing a single pixel line with a vertical gradient?

Link to comment
Share on other sites

vertical gradient

$height = 200;
$xpos = 23;
$ypos = 50;

$c1 = array(0xFF, 0x00, 0x00);
$c2 = array(0x00, 0x00, 0xFF);

$interval = 20;

$im = imagecreatetruecolor(50,300);
$bg = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$border = imagecolorallocate($im, 0x00, 0x00, 0x00);
imagefill($im,0,0,$bg);
imagerectangle($im, 0,0,imagesx($im)-1,imagesy($im)-1,$border);
imagesetthickness($im, 4);

$y1 = $ypos;
for ($y2 = $ypos+$interval; $y2 <= $ypos+$height; $y2+=$interval) {
   $c=array();
   for ($i=0; $i<3; $i++) {
    $c[$i] = $c1[$i] + ($c2[$i]-$c1[$i])*($y2-$ypos)/$height;
   }

   $col = imagecolorallocate($im, $c[0], $c[1], $c[2]);
   imageline($im, $xpos, $y1, $xpos, $y2, $col);
   $y1 = $y2;
}

header("content-type: image/png");
imagepng($im);
imagedestroy($im);

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.