codewithkyle / jitter-core
一个受Imgix启发的图像转换库。
2.0.1
2022-07-07 18:42 UTC
Requires
- php: ^7.2|^8.0
README
Jitter是一个基于Imgix API的图像转换库。该库被创建为一个简单且免费的Imgix风格服务的替代品。它不提供其他服务/库所提供的所有功能。如果您需要比基本的图像转换更高级的功能,我建议您为Imgix付费。
要求
此库需要PHP 7.2或更高版本以及ImageMagick。
安装
# Install the library via composer composer require codewithkyle/jitter-core # Optional webp support (recommended) sudo apt install webp
使用Jitter
转换图像
use codewithkyle\JitterCore\Jitter; class ImageController { public function transformImage() { $imageFilePath = "./image.jpg"; // copy of source image (will be overwritten) $params = ["w" => 320, "ar" => "1:1", "fm" => "jpg"]; // See transformation parameter table below for more options $transformSettings = Jitter::BuildTransform($params); // Transform settings can be hashed with the base image's indentifier when caching Jitter::TransformImage($imageFilePath, $transformSettings); // Manipulates and overwrites the image located at $imageFilePath // Optional Next Steps: // Save $imageFilePath a cloud provider (such as S3) } }
转换参数
auto
格式类型将在服务器可以生成该格式且客户端浏览器支持该格式时返回webp
图像。