


PHP image processing class phpThumb parameter usage introduction
Several basic parameters of phpThumb
List some useful parameters:
src: The address of the target image
w: The width of the output image
h: The height of the output image (if you do not specify it Will be scaled according to the w parameter)
q: If the output is in JPG format, you can specify its output quality
bg: The background during output (if necessary)
sw, sh, sx, sy: Partial output, width, height, starting position
f: Output format, can be jpeg, png, gif, ico
sfn: Output a certain frame in the gif animation
fltr[]: Filter, can There are many effects, including sharpening, blurring, rotation, watermark, border, masking, color adjustment, etc.
For more effects, please refer to the official routine:
http://phpthumb.sourceforge.net/demo/ demo/phpThumb.demo.demo.php
Use phpThumb and .htaccess to cache thumbnails
Principle: The user visits a URL like your.com/thumbs/images/image.50×50.jpg, and the script generates your .com/images/image.jpg thumbnail and save it to your.com/thumbs/images/image.50×50.jpg. You don’t need to adjust PHP next time you visit.
Introduction
About a year ago I came across this awesome script called phpThumb, an open source project for scaling images. Of course you can use GD2 or imagemagick(magickwand) to do the same thing, but phpThumb is designed for this. It is quite simple to use:
If the number of visits is large, it will not be able to sustain it, because apache It is necessary to adjust PHP to parse the phpThumb code for each image request. Even though phpThumb has its own cache, it still has to call PHP to decide whether to read from the cache.
I once saw someone use mod_rewrite to redirect non-existent images to a script that can generate thumbnails to solve performance problems:
You need:
Apache
mod_rewrite
PHP
These things are usually available in virtual hosts. How to install them is beyond the scope of this article.
OK, tell me how to do it!
Upload phpThumb
Download phpThumb from here: http://phpthumb.sourceforge.net/ and upload it to yoursite.com/phpthumb
Configure Mod_Rewrite
New yoursite.com/thumbs/.htaccess :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index. php?thumb=$1 [L,QSA]
New thumbnail generation script:
New yoursite.com/thumbs/index.php
$thumb = $_GET['thumb']; if (!$thumb) { exit; } // $thumb_array = explode('.',$thumb); $image = '../'; foreach($thumb_array as $k=>$thumb_part){ if ($k != count($thumb_array)-2) { $image .= $thumb_part . '.'; } } $image = substr($image,0,-1); list($width,$height) = explode('x',$thumb_array[count($thumb_array)-2]); // if (file_exists($image)) { require('../phpthumb/phpthumb.class.php'); $phpThumb = new phpThumb(); $phpThumb->setSourceFilename($image); $phpThumb->setParameter('w',$width); $phpThumb->setParameter('h',$height); //$phpThumb->setParameter('far','C'); // scale outside //$phpThumb->setParameter('bg','<SPAN class=caps>FFFFFF</SPAN>'); // scale outside if ($phpThumb->GenerateThumbnail()) { mkdir(dirname($thumb),0777,true); if ($phpThumb->RenderToFile($thumb)) { header('Location: /thumbs/'.$thumb); exit; } } }
Test it!
Upload an image to yoursite.com/images/myimage.jpg
Open your browser and visit yoursite.com/thumbs/images/myimage.100×100.jpg
Check the thumbs directory, it should There's a thumbnail there. There is no need to adjust PHP next time you visit.
For more PHP image processing classes, please pay attention to the PHP Chinese website for related articles introducing the usage of phpThumb parameters!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
