Hi all, I'm trying to make a script that will take a value (H) then blend from gray to black, but it only says Could not set BG when I run the script.

Code is listed below.

<?php

 $im = imagecreate(10,$_GET['H'])
   or die("Cannot Initialize new GD image stream");

 $Start = 192;

 $End = 0;

 $Inc = (($End - $Start) / $_GET['H']);

// This next line's the problem.
 $background_color = imagecolorallocate ($im, $Start, $Start, $Start)
 or die ("Could not set BG");

 $x1 = 0; //originating vertical X coordinate
 $y1 = 0; //originating horizontal Y coordinate

 $x2 = 1; //target vertical X coordinate
 $y2 = 1; //target horizontal Y coordinate

 for($a=1;$a<=$_GET['H'];$a++)
  {

   //move the line along one pixel
   $x1 += 1;
   $x2 += 1;

   //change color variable
   $Start += $Inc;

   $NewColour = imagecolorallocate($im, $Start, $Start, $Start);
   imageline($im,$x1,$y1,$x2,$y2,$NewColour);
  }

 header("Content-type:image/png");
 ImagePng($im);

?>

Andrew.

    Personally, I'd use a truecolor image ([man]imagecreatetruecolor/man) and just use [man]imagecolorclosest/man.
    Also, I'd recommend taking out the [FONT=courier new]or die()[/FONT] and seeing what PHP says the error is.

    [By the way, Farscape ROCKS!]

      Originally posted by Mordecai
      Personally, I'd use a truecolor image ([man]imagecreatetruecolor/man) and just use [man]imagecolorclosest/man.
      Also, I'd recommend taking out the [FONT=courier new]or die()[/FONT] and seeing what PHP says the error is.

      [By the way, Farscape ROCKS!]

      I didn't have in the die bit, and it just generated a transparent image... Not exactly what I want :p

      But thanks for the other tip, I'll look into it.

      Edit: My server doesn't have GD2.0 installed, so I can't use imagecreatetruecolor 🙁

      Andrew.

        Write a Reply...