imagecolorallocate - No Effect

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • afrinspray

    imagecolorallocate - No Effect

    I'm having trouble with the imagecoloralloc ate function. I'm creating
    a security image, and the color of the text changes depending on the
    background for some reason (ie, for one background the text is always
    black, one is always pink, and the other is always yellow).

    Any ideas? I'm running Freebsd.

    Here's my code:

    <?php

    include_once('s ession.php');
    include_once('f unctions.php');

    $strCode = randomcode(6);
    $_SESSION['strCode'] = $strCode;

    $bgdir = 'images/verification/';
    $bgs = array('bg1.png' , 'bg2.png', 'bg3.png');
    $im = ImageCreateFrom PNG($bgdir.$bgs[rand(0, count($bgs)-1)]);

    $font = '/usr/X11R6/lib/X11/fonts/urwfonts-ttf/n021003l.ttf';

    $size = rand(12, 16);
    $angle = rand(-5, 5);
    //$color = ImageColorAlloc ate($im, rand(0, 50), rand(0, 50), rand(0,
    50));
    $color = imagecoloralloc ate($im, 0, 0, 0);

    $textsize = imagettfbbox($s ize, $angle, $font, $strCode);
    $twidth = abs($textsize[2]-$textsize[0]);
    $theight = abs($textsize[5]-$textsize[3]);
    $x = (imagesx($im)/2)-($twidth/2)+(rand(-20, 20));
    $y = (imagesy($im))-($theight/2);

    imagettftext($i m, $size, $angle, $x, $y, $color, $font, $strCode);

    header("Content-Type: image/png");
    imagepng($im);

    imagedestroy($i m);

    exit;

    ?>

    Thanks,
    Mike

  • Mike Youell

    #2
    Re: imagecoloralloc ate - No Effect


    I couldn't reproduce this. The text was always black for me, as
    expected due to the imagecoloralloc ate($im, 0, 0, 0).

    I'm developing on Mac OS X using Safari web browser so maybe it's
    something specific with FreeBSD or your web browser?

    Comment

    • afrinspray

      #3
      Re: imagecoloralloc ate - No Effect

      Thanks for trying it out. Last night I resolved the problem by changing
      the resolution of the background png images. Does the
      imagecoloralloc ate use the color pallette of the image resource you
      give it?

      Mike

      Comment

      • Mike Youell

        #4
        Re: imagecoloralloc ate - No Effect

        Looking at the documentation
        (http://uk2.php.net/manual/en/functio...orallocate.php) it seems
        to imply that it does use the color pallette of the image resource.
        [color=blue]
        >From documentation: "imagecolorallo cate() must be called to create each[/color]
        color that is to be used in the image represented by image."

        Comment

        • afrinspray

          #5
          Re: imagecoloralloc ate - No Effect

          This is as confusing as legal documentation. :)

          But thanks... that must be what happenned. 0,0,0 must have been light
          pink and light yellow in my first, low-quality png's pallettes.

          Mike

          Comment

          • Mike Youell

            #6
            Re: imagecoloralloc ate - No Effect


            I'm glad you found the documentation confusing as well. I thought I
            was just being thick ;o)

            Comment

            Working...