douyasi/image-resizer

此包已被废弃,不再维护。作者建议使用 https://github.com/WookieMonster/Laravel-Image-Resizer 包。

Laravel 图片缩放器

此包尚未发布版本,信息较少。


README

主要功能

  • 基于宽度或高度保留当前比例进行缩放
  • 使用最短边从中心自动裁剪图片
  • 旋转
  • 过滤器(对比度、亮度、平滑、灰度、高斯)
  • 支持 jpg、png 和 gif 的加载和导出
  • 自动生成文件名或自定义文件名

安装包后,请确保将 'WookieMonster\ImageResizer\ImageResizerServiceProvider' 添加到 app/config/app.php 中的 providers 数组。包已经包含了一个名为 ImageResizer 的别名定义。

示例

使用外观加载图片

$resizer = ImageResizer::load('path/to/image.jpg');

自动裁剪图片为 2:1 的矩形

$resizer->autocrop(2, 1)->export('/path/to/save/destination');

自动裁剪图片为 1:1(正方形)并将宽度调整为 200,保持宽高比

$resizer->autocrop(1, 1)->resizeWidth(200)->export('/path/to/save/destination');

从 x = 50, y = 20, 宽度和高度为 100 的区域裁剪

$resizer->crop(50, 20, 100, 100)->greyscale()->export('/path/to/save/destination');

按比例缩放图片,使用其宽度或高度

// using the width and scaling the height proportionally:
$resizer->resizeWidth(100);
// OR using the height and scaling the width proportionally:
$resizer->resizeHeight(100);

旋转图片

$resizer->rotate(90)->export('/path/to/save/destination', 'myfilename', 'png');

默认情况下,导出会创建一个随机的 32 位字符文件名

resizer->export('/path/to/save/destination');

要指定文件名,请将其包含在第二个参数中

resizer->export('/path/to/save/destination', 'myfilename');

使用第三个参数指定导出文件类型

resizer->export('/path/to/save/destination', FALSE, 'png'); // saves png format

图片导出后,使用获取器获取有关文件的有用信息

$resizer->getExif(); // exif data about the original file
$resizer->getWidth(); // exported width
$resizer->getHeight(); // exported height
$resizer->getFullSavePath(); // full absolute path "/absolute/path/to/myfilename.jpg"
$resizer->getSavedFilename(); // saved filename e.g. "myfilename"
$resizer->getSavedFilenameWithExtension(); // saved filename including extension e.g. "myfilename.jpg"

许可证: https://open-source.org.cn/licenses/gpl-license.php GNU 公共许可证