Results 1 to 4 of 4

Thread: Is there a limit on how many timed the GD function 'imageline' can be called?

  1. #1
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Is there a limit on how many timed the GD function 'imageline' can be called?

    I've made a file that returns an image of 1px multicoloured vertical lines.
    The default height, width, colour and variance can be overridden with url variables.

    The image can be called like this:
    HTML Code:
    <img src="linebar.php" />
    With variables:
    HTML Code:
    <img src="linebar.php?w=300&h=100&c[]=123&c[]=43&c[]=204&v[]=19&v[]=65&v[]=37" />
    When I use this file to create an image, the lines only go to a width of 255px, the rest of the image is filled with black (the background colour).
    Is this the max number of times imageline can be called?

    The file used for generating the image is here:
    PHP Code:
    <?php

    #height
    if(!($h=@$_GET["h"]))$h=50;
    #width
    if(!($w=@$_GET["w"]))$w=200;
    #colour
    if(!($c=@$_GET["c"]))$c=array(255,255,255);
    #variance (array of {how much red varies, green's variance, ...} )
    if(!($v=@$_GET["v"]))$v=array(255,255,255);

    #get a random variance of a colour
    function randomColour($colour,$variance){
    #this is keeping the colour in acceptable margins (0 <= colour <= 255)
        
    if($colour-$variance<0){
            
    $colour+=rand(0,$variance);
        }else if(
    $colour+$variance>255){
            
    $colour-=rand(0,$variance);
        }else{
            
    $colour+=rand(-$variance,$variance);
        };
        return 
    $colour;
    };

    #tell browser to expect a jpeg
    header('Content-Type: image/jpeg');

    #make the base image
    $image imagecreate($w,$h);

    #fill image with black
    imagecolorallocate($image000);

    #for each pixel in width
    for($i=0;$i<$w;$i++){
        
    #draw a vertical line with a randomed colour
        
    imageline($image$i0$i$himagecolorallocate($imagerandomColour($c[0],$v[0]), randomColour($c[1],$v[1]), randomColour($c[2],$v[2])));
    };

    #output the jpeg
    imagejpeg($image);

    #destroy the image to free memory
    imagedestroy($image);

    ?>
    Last edited by legomanlachlan; 12-16-2008 at 12:08 AM. Reason: Giving more details

  2. #2
    Join Date
    Sep 2008
    Posts
    56
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default RE: - Is there a limit on how many timed the GD function 'imageline' can be called?

    Hi,

    There is no limit to the number of times you can call imageline(), to me it sounds like that there is some problem with the randomColor(), try to change the range you have specified in randomly creating the code for the color. As after a stage it start getting codes which will only produce black color.

    Cheers,

    ~Maneet
    Lexolution IT Services
    Web Design Services

  3. #3
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I found out why, it's because I made the image with imagecreate and not imagecreatetruecolor. imagecreate must have a 256 color limit.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Good that you figured it out, and I can confirm there is a 256 color limit.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •