Php: How to dynamically generate thumbnails and output the Display _ PHP Tutorial

Source: Internet
Author: User
Php dynamically generates thumbnails and outputs the display method. The following describes how to dynamically generate and display thumbnails in php and how to output and display thumbnails in php. it involves some php image-related skills, very practical value: php dynamic generation of thumbnails and output of display methods

The following describes how to dynamically generate and display thumbnails in php. it involves some php image-related skills and is very useful. For more information, see

This example describes how php dynamically generates thumbnails and outputs the display. Share it with you for your reference. The details are as follows:

Call method:

?

1

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:

?

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, $ width, $ height, $ width_orig, $ height_orig );

// Output

Imagejpeg ($ image_p, null, 100 );

// Imagedestroy

Imagedestroy ($ image_p );

?>

I hope this article will help you with php programming.

The following section describes how to dynamically generate thumbnails and display thumbnails in php. it involves php image-related skills and is very useful...

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.