The following introduces you to the method of dynamically generating thumbnails in php and outputting the display, involving related skills of php operating pictures, which is very It has practical value, friends in need can refer to it
The example in this article describes the method of dynamically generating thumbnails in php and outputting them for display. Share it with everyone for your reference. The details are as follows:
Calling method:
?
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$filename= $_GET['filename']; $width = $_GET['width']; $height = $_GET['height']; $path="http://localhost/images/"; //finish in "/" // Content type header('Content-type: image/jpeg'); // Get new dimensions list($width_orig, $height_orig) = getimagesize($path.$filename); if ($width && ($width_orig < $height_orig)) { $width = ($height / $height_orig) * $width_orig; } else { $height = ($width / $width_orig) * $height_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($path.$filename); imagecopyresampled($image_p,$image,0,0,0,0,$width,$height,$width_orig,$height_orig); // Output imagejpeg($image_p, null, 100); // Imagedestroy imagedestroy ($image_p); ?> |
The thumbs.php file is as follows:
?
1 8 9 |
<🎜>$filename= $_GET['filename'];<🎜> <🎜>$width = $_GET['width'];<🎜> <🎜>$height = $_GET['height'];<🎜> <🎜>$path="http://localhost/images/"; //finish in "/"<🎜> <🎜>// Content type<🎜> <🎜>header('Content-type: image/jpeg');<🎜> <🎜>// Get new dimensions<🎜> <🎜>list($width_orig, $height_orig) = getimagesize($path.$filename);<🎜> <🎜>if ($width && ($width_orig < $height_orig)) {<🎜> <🎜>$width = ($height / $height_orig) * $width_orig;<🎜> <🎜>} else {<🎜> <🎜>$height = ($width / $width_orig) * $height_orig;<🎜> <🎜>}<🎜> <🎜>//Resample<🎜> <🎜>$image_p = imagecreatetruecolor($width, $height);<🎜> <🎜>$image = imagecreatefromjpeg($path.$filename);<🎜> <🎜>imagecopyresampled($image_p,$image,0,0,0,0,$width,$height,$width_orig,$height_orig);<🎜> <🎜>//Output<🎜> <🎜>imagejpeg($image_p, null, 100);<🎜> <🎜>// Imagedestroy<🎜> <🎜>imagedestroy ($image_p);<🎜> <🎜>?> |