I have installed gd graphic library on a linux pc, who could tell me how to check if the installing is right or not? If there are some sample php code using gd library, I could put it on my pc to see if gd library works or not. Thanks!
Printable View
I have installed gd graphic library on a linux pc, who could tell me how to check if the installing is right or not? If there are some sample php code using gd library, I could put it on my pc to see if gd library works or not. Thanks!
Here are a couple of examples you can try:
PHP Code:<?php
// Set the path to the image to resize
$input_image = "House.jpg";
// Get the size of the original image into an array
$size = getimagesize( $input_image );
// Set the new width of the image
$thumb_width = "200";
// Calculate the height of the new image to keep the aspect ratio
$thumb_height = ( int )(( $thumb_width/$size[0] )*$size[1] );
// Create a new true color image in the memory
$thumbnail = ImageCreateTrueColor( $thumb_width, $thumb_height );
// Create a new image from file
$src_img = ImageCreateFromJPEG( $input_image );
// Create the resized image
ImageCopyResampled( $thumbnail, $src_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $size[0], $size[1] );
// Save the image as resized.jpg
ImageJPEG( $thumbnail, "resized.jpg" );
// Clear the memory of the tempory image
ImageDestroy( $thumbnail );
?>
<img src="resized.jpg">
PHP Code:<?php
// Create a new image in the memory from the file
$png_image = imagecreatefrompng( "input.png" );
// Save the image as output.jpg
imagejpeg( $png_image, "output.jpg" );
// Clear the memory of the tempory image
imagedestroy( $png_image );
?>
<img src="output.jpg">
Thank you very much!