SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict Clete2's Avatar
    Join Date
    Mar 2002
    Location
    Columbia, South Carolina
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    GD ImageColorAllocate - Color Guide?

    I've been trying to get some nice colors using ImageColorAllocate(), but I can't find a guide or make the colors I want. Does anyone have a simple tool that will print out some GD color values?
    My Blog
    My Photography Website
    Linux user #339185

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Here's a script I wrote to create a random image - it includes a function to set the common colours. (Note: I wrote this a long time ago so there may be better ways to do this ) ...
    PHP Code:
    <?php
    function setPenColors($theimage) {
        global 
    $redpen$greenpen$bluepen$blackpen$whitepen$yellowpen$aquapen$fuschiapen$greypen$silverpen$tealpen$limepen$navypen$purplepen$maroonpen$olivepen;
        
    $redpen ImageColorAllocate($theimage25500);
        
    $greenpen ImageColorAllocate($theimage01530);
        
    $bluepen ImageColorAllocate($theimage00255);
        
    $blackpen ImageColorAllocate($theimage000);
        
    $whitepen ImageColorAllocate($theimage255255255);
        
    $yellowpen ImageColorAllocate($theimage2552550);
        
    $aquapen ImageColorAllocate($theimage0255255);
        
    $fuschiapen ImageColorAllocate($theimage2550255);
        
    $greypen ImageColorAllocate($theimage153153153);
        
    $silverpen ImageColorAllocate($theimage204204204);
        
    $tealpen ImageColorAllocate($theimage0153153);
        
    $limepen ImageColorAllocate($theimage02550);
        
    $navypen ImageColorAllocate($theimage00153);
        
    $purplepen ImageColorAllocate($theimage1530153);
        
    $maroonpen ImageColorAllocate($theimage15300);
        
    $olivepen ImageColorAllocate($theimage1531530);
    }
    $servername getenv("SERVER_NAME");

    // set the content type
    //header("Content-type:  image/jpeg");
    if ($servername != "localhost" && $servername != "uk07pc21-193" && $servername != "127.0.0.1") {
        
    header("Content-type:  image/gif");
    } else {
        
    header("Content-type:  image/png");
    }

    $imageWidth 118;
    $imageHeight 136;

    // create image
    $image imageCreate($imageWidth$imageHeight);

    $bgcolor ImageColorAllocate($image000);
    $fgcolor ImageColorAllocate($image255255255);
    setPenColors($image);

    srand ((double) microtime() * 1000000);
    $rndnum rand(10,60);
    $oldx rand(1,$imageWidth-2);
    $oldy rand(1,$imageHeight-18);
    $pencolor = array ($redpen,$greenpen,$bluepen,blackpen,$whitepen,$yellowpen,$aquapen,$fuschiapen,$greypen,$silverpen,$tealpen,$limepen,$navypen,$purplepen,$maroonpen,$olivepen);

    $rndpen rand(0,15);
    ImageRectangle($image00$imageWidth-1$imageHeight-17$pencolor[$rndpen]);

    for (
    $i=0$i<$rndnum$i++) {
        
    $rndpen rand(0,15);
        
    $newx rand(1,$imageWidth-2);
        
    $newy rand(1,$imageHeight-18);
        
    ImageLine ($image$oldx$oldy$newx$newy$pencolor[$rndpen]);
        
    $oldx $newx;
        
    $oldy $newy;
    }

    ImageString($image,24$imageHeight-14,  "Random Image Maker"$limepen);

    // create an interlaced image for better loading in the browser
    imageInterlace($image1);

    // mark background color as being transparent
    imageColorTransparent($image$bgcolor);

    // now send the picture to the client (this outputs all image data directly)
    //imageJPEG($image);
    if ($servername != "localhost") {
        
    imageGIF($image);
    } else {
        
    imagePNG($image);
    }

    ?>
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A few GD notes:

    If you are using a version below 2.0, any imagecreate() call will only output a graphic with a palette holdign a maximum of 256 indexes. You can 'feasibly' work around that by using a base image and imagecreatefromJPEG/GIF/PNG/WBMP though.

    If you are using imagecreate and have already defined 256 colours, any further calls to imagecolorAllocate will actually effect the palette index and not just the pixel/area you want. ImagecolorClosest is a helpful alternative. 'tis better to use a workaround and 16million index palette though.

    Did you really just want a tool that will tell you the red,green,blue value of an onscreen pixel?
    If you did, I suggest nattywares pixie
    teckis - that's news to me.

  4. #4
    SitePoint Addict Clete2's Avatar
    Join Date
    Mar 2002
    Location
    Columbia, South Carolina
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks both of you. Pootergerist: yeah that is what i wanted... I think my server is using an older version...

    edit: I think so... in phpinfo, it says 1.6.2 or higher...

    http://clete2.2grecords.com/php/phpinfo.php
    My Blog
    My Photography Website
    Linux user #339185


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
  •