The example in this article describes how PHP uses timthumb to generate thumbnails. 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:
<?php $image = "http://localhost/test/pen_pic03.png"; ?> <html> <head> <title>timthumb</title> </head> <body> <img src="http://localhost/test/timthumb.php?src=<?php echo $image; ?>&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.