它是一个开源的图片缩略图类库,可以完成多种复杂的图片缩略图生成和现实,使用起来非常的方便。
2、使用方法
这里有一篇关于其简单实用的说明,英文比较简单,就不翻译了:
Basic-Usage
3、API
这里有一个API列表:
PHPThumb API
不过非常可惜,API中并没有任何说明,只能对照其英文名称猜测其效果,当然即使猜对了,也要测试下看看是否是正确的。
4、样例
这里我也写了个简单调用它的方法,不过我是把该图片保存成为文件了,basic-usage中的例子全是直接在页面中输出的:
复制代码 代码如下:
require_once 'phpthumb/ThumbLib.inc.php';
try {
$thumb = PhpThumbFactory::create($realpath);
} catch (Exception $e) {
// handle error here however you'd like
}
$thumb->adaptiveResize($width, $height);
$thumb->save($realpath . '.' . $width . 'x' . $height . '.png');
5、我用到的几个API
使用过程中,对几个API的理解逐渐加深,这里记录下:
resize ($maxWidth, $maxHeight)
resize方法是最常用的缩略图方法,它直接等比例将最大的边缩小到符合要求的高度/宽度,当图片宽高比与要求不一致时,将会有边显示空白。
adaptiveResize ($width, $height)
adaptiveResize方法是在一些特定情况下,不要求图片的完整,而要求显示特定宽高的最多内容。具体计算方式是:
当图片宽度大于所要求宽度,而高度一致时,取该高度下,从图片左右的中间去所要求的宽度;
当图片的高度大了并且宽度一致时,去该宽度下,图片上下居中位置取得所要求的高度;
当宽高都不正确时,先将图片缩放到所要求大小,再按前两条执行。
save ($fileName, $format = ‘GIF|JPG|PNG')
当对图片做好处理后,可以用save方法,将图片保存为format中所指示的编码之一,如果未指定编码,将以原编码方式保存。$fileName是要保存的路径。

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

Autoloading in PHP automatically loads class files when needed, improving performance by reducing memory use and enhancing code organization. Best practices include using PSR-4 and organizing code effectively.

PHP streams unify handling of resources like files, network sockets, and compression formats via a consistent API, abstracting complexity and enhancing code flexibility and efficiency.

The article discusses managing file upload sizes in PHP, focusing on the default limit of 2MB and how to increase it by modifying php.ini settings.

The article discusses nullable types in PHP, introduced in PHP 7.1, allowing variables or parameters to be either a specified type or null. It highlights benefits like improved readability, type safety, and explicit intent, and explains how to declar

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec


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

Dreamweaver CS6
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment
