Php dynamically generates thumbnails and outputs the display method

Source: Internet
Author: User
This article mainly introduces how php dynamically generates thumbnails and outputs the display. it involves php image-related skills and is very useful, for more information, see the example in this article. Share it with you for your reference. The details are as follows:

Call method:

 

This code dynamically generates thumbnail display for large images. images are generated in the memory and are not generated on the hard disk.

The thumbs. php file is as follows:

<?php$filename= $_GET['filename'];$width = $_GET['width'];$height = $_GET['height'];$path="http://localhost/images/"; //finish in "/"// Content typeheader('Content-type: image/jpeg');// Get new dimensionslist($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);// Outputimagejpeg($image_p, null, 100);// Imagedestroyimagedestroy ($image_p);?>

I hope this article will help you with php programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.