wiejakp/image-crop

PHP的图片裁剪助手。

v1.0.7 2020-03-03 22:15 UTC

This package is auto-updated.

Last update: 2024-08-29 05:42:16 UTC


README

Source Code Latest Version Software License PHP Version Build Status Coverage Status Total Downloads

本项目遵守贡献者行为准则。参与本项目及其社区,您应遵守此准则。

安装

首选的安装方法是使用Composer。运行以下命令安装包并将其添加到项目的composer.json文件中:

composer require wiejakp/image-crop

基本用法

$imagePath = 'image.jpeg';
  
$imageCrop = (new ImageCrop())
   ->setReader(JPEGReader::class)
   ->setWriter(JPEGWriter::class);

// load resource into a reader
$imageCrop->getReader()->loadFromPath($imagePath);

// perform cropping actions
$imageCrop->crop();

// skip images that appear to be empty
if (false === $imageCrop->isEmpty()) {

   // save cropped image to the drive
   $imageCrop->getWriter()->write();

   // do stuff with $imageCrop->getData() or $imageCrop->getDataUri()
   $anchor = \sprintf('<a href="%s">anchor</a>', $imageCrop->getDataUri());
   ...
}

读取器和写入器

您可以根据需要混合使用加载和生成的图片资源。

BMP读取器和写入器
$imageCrop = (new ImageCrop())
   ->setReader(BMPReader::class)
   ->setWriter(BMPWriter::class);
GIF读取器和写入器
$imageCrop = (new ImageCrop())
   ->setReader(GIFReader::class)
   ->setWriter(GIFWriter::class);
JPEG读取器和写入器
$imageCrop = (new ImageCrop())
   ->setReader(JPEGReader::class)
   ->setWriter(JPEGWriter::class);
PNG读取器和写入器
$imageCrop = (new ImageCrop())
   ->setReader(PNGReader::class)
   ->setWriter(PNGWriter::class);

文档

有关详细信息和使用示例,请查看文档网站

贡献

欢迎贡献!请阅读贡献指南以获取详细信息。

版权和许可

wiejakp/ImageCrop库版权© Przemek Wiejak,许可使用MIT许可证(MIT)。有关更多信息,请参阅LICENSE