tigron / skeleton-file-picture
Tigron 文件工具
v0.2.20
2023-09-28 14:48 UTC
Requires
README
描述
此库可以调整图像大小。图像类型必须为 \Skeleton\File\File
安装
通过 composer 安装
composer require tigron/skeleton-file-picture
在数据库中创建一个新表
CREATE TABLE IF NOT EXISTS `picture` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`file_id` int(11) NOT NULL,
`width` int(11) NOT NULL,
`height` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `file_id` (`file_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
如何操作
检查 \Skeleton\File README 初始化文件存储
初始化图像库
/**
* This function adds a picture configuration
*
* $params = [
* 'width' => width in px,
* 'height' => height in px
* 'mode' => exact/crop/auto
* exact => The $height/$width will be used, ratio is ignored
* crop => The image is cropped in in order to fill the $height/$width frame
* auto => The image is resized to fit the $height/$width frame, ratio is kept
* 'format' => image/jpeg|image/gif|image/png|image/webp|original
*/
\Skeleton\File\Picture\Config::add_configuration($params);
/**
* Set the cache path
* This is default set to the system TMP path
*
* \Skeleton\File\Picture\Config::$tmp_dir is deprecated
*/
\Skeleton\File\Picture\Config::$tmp_path = $your_very_temporary_path
显示调整大小的图像
$picture = Picture::get_by_id(1);
$picture->resize($configuration_name);