PHP GD2 library inconsistant

Discussion in 'PHP' started by ThomWilhelm, Jul 8, 2009.

  1. #1
    Hello there, I am usually quite good at debugging PHP problems, but this one has me stumped. I have a website which generates a image which is a different colour based upon the variables:

    $hue = $_GET['hue'];
    $size = $_GET['size'];
    $kitNo = $_GET['kitNo'];

    The code for it is below:

    $ar=array(0,0,0,0);
    srand($hue);
    $onetwoorthree=rand(0,2);
    $first=rand(0,100)/100;
    $second=1-$first;

    $ar[$onetwoorthree]=$first;
    $ar[$onetwoorthree+1]=$second;
    if ($onetwoorthree+1>2)
    $ar[0]=$second;

    $im = imagecreatefromjpeg("../images/kits/top_Normal" . "$kitNo" . ".jpg") or die ("Error");

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

    $height=imagesy($im);
    $width=imagesx($im);
    $im2=imagecreatetruecolor($width,$height);
    for ($x=0;$x<$width;$x++){
    for ($y=0;$y<$height;$y++){
    $rgb = ImageColorAt($im, $x, $y);
    $r = ($rgb >> 16) & 0xFF;
    $g = ($rgb >> 8) & 0xFF;
    $b = $rgb & 0xFF;

    $r2=$r;
    $g2=$g;
    $b2=$b;

    $r=$r2*$ar[0]+$g2*$ar[1]+$b2*$ar[2];
    $g=$r2*$ar[2]+$g2*$ar[0]+$b2*$ar[1];
    $b=$r2*$ar[1]+$g2*$ar[2]+$b2*$ar[0];

    $color = imagecolorallocate($im2, $r, $g, $b);

    imagesetpixel($im2,$x,$y,$color);
    }
    }
    $final = $im2;
    if($size == "Mini") {
    $final = imagecreate(15,10);
    imagecopyresampled($final,$im2,0,0,0,0,15,10,30,20);
    }
    imagejpeg($final,NULL,100);
    ?>

    When run on a windows Windows server it outputs different colours compared to when installed on an Ubuntu server, both have the GD2 library and php5. Any ideas as to why this would happen?
     
    ThomWilhelm, Jul 8, 2009 IP
  2. ThomWilhelm

    ThomWilhelm Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ok, here is some more information, I originally found the script here:

    http://www.phpbuilder.com/snippet/download.php?type=snippet&id=1732

    It seems the problem is during the bitshift operations, removing them both produces the same image on both servers.
     
    ThomWilhelm, Jul 8, 2009 IP
  3. anthonywebs

    anthonywebs Banned

    Messages:
    657
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Maybe the gd2 lib is progrmmed a little diff in ubuntu than windows cause they have diff program langs
     
    anthonywebs, Jul 8, 2009 IP