php thumbnail function code

  • 2020-05-07 19:23:33
  • OfStack

array getimagesize (string $filename [, array &$imageinfo]) gets the image size
resource imagecreatetruecolor (int $x_size, int $y_size) creates a new true color image
resource imagecreatefromjpeg (string $filename) creates a new 1 image from the JPEG file or URL
bool imagecopyresized (resource $dst_image, resource $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_w, int $dst_h, int $src_w, int $src_h) copy part of the image and resize it
bool imagejpeg (resource $image [, string $filename [, int $quality]]) outputs an image to a browser or file in JPEG format
 
<?php 
/* 
Created by <A href="http://www.cnphp.info">http://www.cnphp.info</A> 
*/ 
//  File and zoom size  
//$imgfile = 'smp.jpg'; 
//$percent = 0.2; 
header('Content-type: image/jpeg'); 
list($width, $height) = getimagesize($imgfile); 
$newwidth = $width * $percent; 
$newheight = $height * $percent; 
$thumb = ImageCreateTrueColor($newwidth,$newheight); 
$source = imagecreatefromjpeg($imgfile); 
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 
imagejpeg($thumb); 
?> 

Related articles: