kisphp / thumbnails
Kisphp 缩略图生成器。支持 jpg, png, gif, webp 图片格式
1.6.1
2024-04-28 00:36 UTC
Requires
- php: >=7.4
- ext-exif: *
- ext-gd: *
Requires (Dev)
- phpunit/phpunit: ~9.5
- symfony/var-dumper: ~3.4|~5.0
This package is auto-updated.
Last update: 2024-09-14 12:41:28 UTC
README
这个类可以帮助您轻松调整图片大小,并将其保存到磁盘或显示给用户
支持的格式
- jpg
- jpg2000
- png
- gif
- webp
安装
composer require kisphp/thumbnails
然后添加确保您加载了 composer 自动加载器
require_once 'path/to/vendor/autoload.php';
用法
<?php
require_once 'path/to/vendor/autoload.php';
$image = new \Kisphp\ImageResizer();
// load original image file
$image->load('/path/to/image/file.jpg');
// set where thumbnail will be saved (optional)
$image->setTarget('/path/to/thumbnail/file.jpg');
// resize image to a 300px width and dynamic height by aspect ratio
$image->resize(300, 0);
// or
// resize image to a 300px height and dynamic width by aspect ratio
$image->resize(0, 300);
// show image and save
$image->display(true);
更改缩略图背景颜色
如果您裁剪了图片,可以使用自定义背景颜色将缩略图整合到设计中
// set default background color (here will be red, default is white)
$image->setBackgroundColor(255, 0, 0);
调整大小方法的使用
$image->resize(new_width, new_height, crop_image=true|false);
显示图片但不保存它
$image->display();
注意,这些方法输出
header('Content-Type: image/..mime-type..')