kenura / imagick
图片调整大小、压缩和添加水印工具
v1.0.0
2023-12-15 15:09 UTC
Requires
- ext-imagick: ^3.7
README
该库是使用Imagick
PHP扩展创建的,专注于使用简单方法进行图像处理。
要求
- PHP扩展
ext-imagick
版本 > 3.7
安装
使用Composer安装Imagick Image Processor,请运行以下命令
composer require kenura/imagick
方法
调整大小
resizeImage
方法可以根据指定的宽度和高度调整图片大小。
public function resizeImage($inputImagePath, $outputImagePath, $width, $height);
压缩
compressToJpg
方法可以将图片压缩为JPEG格式,并指定质量。
public function compressToJpg($inputImagePath, $outputImagePath, $quality = 80);
水印
addWatermark
方法可以添加水印到图片中,有各种定位选项,并保持水印的宽高比。
public function addWatermark($inputImagePath, $outputImagePath, $watermarkImagePath, $position = 'center', $widthPercent = 10, $heightPercent = 10);
透明度
addOpacity
方法可以使图片具有指定的透明度百分比,并以PNG格式保存。
public function addOpacity($inputImagePath, $outputImagePath, $opacityPercent);
调整大小-压缩
resizeAndCompress
方法结合了图片调整大小和压缩功能。
public function resizeAndCompress($inputImagePath, $outputImagePath, $width, $height, $quality = 80);
调整大小-水印-压缩
resizeWatermarkAndCompress
方法结合了图片调整大小、添加水印和压缩功能。
public function resizeWatermarkAndCompress($inputImagePath, $outputImagePath, $width, $height, $watermarkImagePath, $position = 'center', $widthPercent = 10, $heightPercent = 10, $quality = 80);
用法
use YourNamespace\ImageProcessor; // Create an instance of the ImageProcessor $imageProcessor = new ImageProcessor(); // Use the methods based on your requirements $imageProcessor->resizeImage($inputImagePath, $outputImagePath, $width, $height); $imageProcessor->compressToJpg($inputImagePath, $outputImagePath, $quality); $imageProcessor->addWatermark($inputImagePath, $outputImagePath, $watermarkImagePath, $position, $widthPercent, $heightPercent); $imageProcessor->addOpacity($inputImagePath, $outputImagePath, $opacityPercent); $imageProcessor->resizeAndCompress($inputImagePath, $outputImagePath, $width, $height, $quality); $imageProcessor->resizeWatermarkAndCompress($inputImagePath, $outputImagePath, $width, $height, $watermarkImagePath, $position, $widthPercent, $heightPercent, $quality);
感谢
感谢@kenuragunarathna@gmail.com使用这个库!
欢迎贡献或报告问题。