Home >Backend Development >PHP Tutorial >How to use timthumb to generate thumbnails in php_php tips

How to use timthumb to generate thumbnails in php_php tips

WBOY
WBOYOriginal
2016-05-16 19:59:361000browse

The example in this article describes how to use timthumb to generate thumbnails in PHP. Share it with everyone for your reference, the details are as follows:

There are two ways to generate thumbnails:

1. Generate it in advance for calling

The common practice for thumbnails is to start with how many types of thumbnails you want to generate based on the image specifications on the website. The thumbnails will be generated during the image upload process for different needs. One disadvantage of this method is that if you increase the image specifications, the previously uploaded images do not have the specifications and will have to be regenerated.

2. Generate thumbnails when calling. This is why I wrote this article.

I recommend timthumb. Personally, I think this thing is definitely easy to use without considering performance and efficiency.

1, download address: http://timthumb.googlecode.com/svn/trunk/timthumb.php

2. How to use

After downloading, put it in your web environment, create a cache folder in the directory parallel to timthumb.php, and give it 755 permissions. If you are using Windows, you don’t need it. The test code is as follows:

<&#63;php
$image = "http://localhost/test/pen_pic03.png";
&#63;>
<html>
<head>
<title>timthumb</title>
</head>
<body>
 <img src="http://localhost/test/timthumb.php&#63;src=<&#63;php echo $image; &#63;>&w=58&h=46&zc=1" alt="" />
</body>
</html>

Parameter description:

w=58 means the image width is 58
h=46 means the image height is 46

You can set it up as needed.

The biggest advantage of timthumb is convenience. I have not encountered such a tool so far. The shortcomings are equally obvious. Every time a request is made, php-cgi or php-cli will be called, and the cached data will be placed in the cache directory. When calling data, you have to search the directory, and the performance will be relatively low.

I hope this article will be helpful to everyone in PHP programming.

Statement:
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