RE: Configuring PHP with GD and JPEG support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Just tried it with the following but still fails.  All I'm getting is a blank page.

<php?
function create_image()
{
     //Let's generate a totally random string using md5
     $md5_hash = md5(rand(0,999));
     //We don't need a 32 character long string so we trim it down to 5
     $security_code = substr($md5_hash, 15, 5);

     //Set the session to store the security code
     $_SESSION["security_code"] = $security_code;

     //Set the image width and height
     $width = 100;
     $height = 20;

     //Create the image resource
     $image = ImageCreate($width, $height);

     //We are making three colors, white, black and gray
     $white = ImageColorAllocate($image, 255, 255, 255);
     $black = ImageColorAllocate($image, 0, 0, 0);
     $grey = ImageColorAllocate($image, 204, 204, 204);

     //Make the background black
     ImageFill($image, 0, 0, $black);

     //Add randomly generated string in white to the image
     ImageString($image, 3, 30, 3, $security_code, $white);

     //Throw in some lines to make it a little bit harder for any bots to break
     ImageRectangle($image,0,0,$width-1,$height-1,$grey);
     imageline($image, 0, $height/2, $width, $height/2, $grey);
     imageline($image, $width/2, 0, $width/2, $height, $grey);

     //Tell the browser what kind of file is come in
     header("Content-Type: image/jpeg");

     //Output the newly created image in jpeg format
     ImageJpeg($image);

     //Free up resources
     ImageDestroy($image);
}

create_image();

?>

> From: karl@xxxxxxxxxxxxxxx
> Date: Mon, 10 Jan 2011 17:10:35 -0600
> To: php-db@xxxxxxxxxxxxx
> Subject: Re:  Configuring PHP with GD and JPEG support
> 
> 
> On Jan 10, 2011, at 9:35 AM, mike dorian wrote:
> 
> >
> > Hello,
> >
> > Questions with regards to compiling PHP to support GD with JPEG on  
> > 64-bit CentOS 5.5.
> >
> > 1) Specifying folder for jpeg library
> > When I execute the following command, am I saying the full path to  
> > libdir is at /usr/source/lib64?
> > ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-gd -- 
> > with-jpeg-dir=/usr/source --with-libdir=lib64
> >
> > Should I have done the following instead?
> > ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-gd -- 
> > with-jpeg-dir=/usr/source/lib64
> >
> >
> > 2) After copying the compiled JPEG libraries to the the lib64  
> > directory, PHP is still unable to call the GD functions (ie  
> > ImageCreateFromJpeg) properly.
> > Once I've done the following.
> > ./configure --enable-shared
> > make
> > make install
> >
> > I have the following files installed.  Meanwhile the /usr/local/ 
> > lib64 directory doesn't have these files.  Despite copying the  
> > whole set to /usr/local/lib64, the above configure command still  
> > doesn't work.
> > /usr/local/lib/libjpeg.a
> > /usr/local/lib/libjpeg.la
> > /usr/local/lib/libjpeg.so -> libjpeg.so.8.0.2
> > /usr/local/lib/libjpeg.so.8 -> libjpeg.so.8.0.2
> > /usr/local/lib/libjpeg.so.8.0.2
> >
> > The following displays a blank page on my Firefox.
> > <?php
> > header('Content-Type: image/jpeg');
> >   $image_file_path = '/usr/local/apache2/htdocs/image.jpg';
> >   $image_file_path";
> >   $im = @ImageCreateFromJpeg($image_file_path)";
> >   echo "$im";
> >   imagejpeg($im);
> >   echo "End: imagedestroy($im)";
> > ?>
> >
> >  		 	   		
> 
> 
> Hi Mike,
> Dont know about your server config, but maybe try using this create  
> image script and see.
> 
> function create_image()
> {
>      //Let's generate a totally random string using md5
>      $md5_hash = md5(rand(0,999));
>      //We don't need a 32 character long string so we trim it down to 5
>      $security_code = substr($md5_hash, 15, 5);
> 
>      //Set the session to store the security code
>      $_SESSION["security_code"] = $security_code;
> 
>      //Set the image width and height
>      $width = 100;
>      $height = 20;
> 
>      //Create the image resource
>      $image = ImageCreate($width, $height);
> 
>      //We are making three colors, white, black and gray
>      $white = ImageColorAllocate($image, 255, 255, 255);
>      $black = ImageColorAllocate($image, 0, 0, 0);
>      $grey = ImageColorAllocate($image, 204, 204, 204);
> 
>      //Make the background black
>      ImageFill($image, 0, 0, $black);
> 
>      //Add randomly generated string in white to the image
>      ImageString($image, 3, 30, 3, $security_code, $white);
> 
>      //Throw in some lines to make it a little bit harder for any  
> bots to break
>      ImageRectangle($image,0,0,$width-1,$height-1,$grey);
>      imageline($image, 0, $height/2, $width, $height/2, $grey);
>      imageline($image, $width/2, 0, $width/2, $height, $grey);
> 
>      //Tell the browser what kind of file is come in
>      header("Content-Type: image/jpeg");
> 
>      //Output the newly created image in jpeg format
>      ImageJpeg($image);
> 
>      //Free up resources
>      ImageDestroy($image);
> }
> 
> Was taken from the WebCheatSheet.com - Create CAPTCHA Protection.
> Namely to see how they are using the ImageJpeg, not the whole code.
> But, at least you will have a code you know produces an image if  
> anything and
> you can shorten the things on the list to check. ;)
> HTH,
> 
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
 		 	   		  

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux