PHP Developers Network
http://forums.devnetwork.net/

[Solved] Imagecolorallocate
http://forums.devnetwork.net/viewtopic.php?f=32&t=36919
Page 1 of 1

Author:  Grim... [ Mon Aug 15, 2005 9:28 am ]
Post subject:  [Solved] Imagecolorallocate

Syntax: [ Download ] [ Hide ]
$color = imagecolorallocate($im, 0, 0, 0);



imageline($im, 5, 19, 66, 867, $color);

imageline($im, 54, 65, 543, 543, $color);  

imageline($im, 55, 3, 1, 166, $color);  

imageline($im, 98, 12, 543, 1, $color);


That should draw 4 black lines, right?

Well, it seems to make the lines any color it likes (although they are alll the same color) - white, red, in fact pretty much anything except for black :(

Have I got this function totally wrong, or what?

Author:  theda [ Mon Aug 15, 2005 9:46 am ]
Post subject: 


Author:  Grim... [ Mon Aug 15, 2005 9:51 am ]
Post subject: 

No, Black is 255,255,255 (or #FFFFFF).

And the numbers before the color are the line co-ordinates.

Author:  onion2k [ Mon Aug 15, 2005 11:00 am ]
Post subject: 


Author:  onion2k [ Mon Aug 15, 2005 11:01 am ]
Post subject: 


Author:  theda [ Mon Aug 15, 2005 11:12 am ]
Post subject: 


Author:  Grim... [ Mon Aug 15, 2005 11:25 am ]
Post subject: 


Author:  Grim... [ Mon Aug 15, 2005 11:26 am ]
Post subject: 


Author:  onion2k [ Mon Aug 15, 2005 2:02 pm ]
Post subject: 

0,0,0,0 is black if you've got an alpha channel.. but anyway..

I tried this code, and it works fine on my dev machine here. Only I have GD2 rather than GD, so maybe that's an issue..

My code:
Syntax: [ Download ] [ Hide ]
<?php



        $im = imagecreate(1000,600);

        $color = imagecolorallocate($im, 255, 255, 255);

        imagefill($im,0,0,$color);



        $color = imagecolorallocate($im, 0, 0, 0);



        imageline($im, 5, 19, 66, 867, $color);

        imageline($im, 54, 65, 543, 543, $color);  

        imageline($im, 55, 3, 1, 166, $color);  

        imageline($im, 98, 12, 543, 1, $color);



        header("Content-type: image/jpeg");

        imagejpeg($im);



?>


The only thing I can suggest is posting the entire code.. maybe there's a variable change going on somewhere that you've missed.

EDIT: Actually.. are you opening an image and drawing onto it?

Author:  Grim... [ Mon Aug 15, 2005 4:31 pm ]
Post subject: 

Here it is:

Syntax: [ Download ] [ Hide ]
function drawrectangle($image, $tlx, $tly, $brx, $bry)

{  

    //set variable names

    $original_image = $image;

    $filename = "images/user/note/".$image;

    $image = "images/user/cutdown/".$image;

   

    //load original image

    $im = imagecreatefromjpeg($image);

    $color = imagecolorallocate($im, 0, 0, 0);

   

    //draw rectangle

    imageline($im, $tlx, $tly, $brx, $tly, $color);

    imageline($im, $tlx, $bry, $brx, $bry, $color);  

    imageline($im, $tlx, $tly, $tlx, $bry, $color);  

    imageline($im, $brx, $tly, $brx, $bry, $color);

   

    //get image size

    $w = imagesx($im);

    $h = imagesy($im);

   

    //create new image

    $dest = imageCreate($w, $h);

    imagecopy($dest, $im, 0, 0, 0, 0, $w, $h);

    imagejpeg($dest, $filename, 100);

   

    //delete temp images

    imagedestroy($dest);

    imagedestroy($im);

}

Author:  onion2k [ Tue Aug 16, 2005 4:54 am ]
Post subject: 


Author:  Grim... [ Tue Aug 16, 2005 8:27 am ]
Post subject: 

I'm doing 5 shortly, but 3 will be fine for now.

Cheers :)

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/