reviewpush/image-resizer

Laravel 的图片缩放器

1.0.0 2015-09-22 20:33 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:16:02 UTC


README

从以下链接分叉:https://github.com/douyasi/Laravel-Image-Resizer

composer require 代码

"require": {
		"reviewpush/image-resizer" : "^1.0.*"
	}

主要功能

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

安装包后,请确保将 'ReviewPush\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 像素,高 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 公共许可证