How to dynamically generate thumbnails in php and output them for display, php dynamically generate thumbnails_PHP tutorial

WBOY
Release: 2016-07-13 09:56:30
Original
1235 people have browsed it

How to dynamically generate thumbnails in php and output them for display. How to dynamically generate thumbnails in php

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:

<img src="thumbs.php&#63;filename=photo.jpg&width=100&height=100">
Copy after login

This code can dynamically generate thumbnails for large pictures to display. The pictures are generated in memory and do not generate real files on the hard disk

thumbs.php file is as follows:

<&#63;php
$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);
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/987255.htmlTechArticleHow to dynamically generate thumbnails in php and output them for display, php dynamically generates thumbnails. This article describes the example of php dynamically generating thumbnails. Thumbnail and output display method. Share it with everyone for your reference. Tool...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template