maagi/imagine-focalresizer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

maagi/imagine-focalresizer

Composer 安装命令:

composer require maagi/imagine-focalresizer

包简介

Focal point resizing for Imagine

README 文档

README

#ImagineFocalResizer

A tool for Imagine Image manipulation library for PHP to resize its image instances using a central "focal point". The image will always be cropped so that the focal point remains within the resized image. This allows to create versions for different screen sizes while maintaining a "responsive crop".

The focal point defined by x and y coordinates ranging from the left top corner (-1,1) to the right bottom corner (1,-1). The center of the image is at (0,0).

Note: The y-axis has been flipped in version 0.2.0 so that the top edge is at 1 and bottom edge at -1.

The idea comes from Jono Menz's jQuery FocusPoint plugin. Its documentation illustrates how the approach works.

##Installation##

Use Composer to install.

$ composer require maagi/imagine-focalresizer

##Usage##

use Imagine\Gd\Imagine; // or Imagick/Gmagick
use Imagine\Image\ImageInterface;
use Imagine\Image\Box;
use Maagi\ImagineFocalResizer\Resizer;
use Maagi\ImagineFocalResizer\FocalPoint;

$imagine = new Imagine();
$image = $imagine->open('dragonfly.jpg');

$resizer = new Resizer();

$resizer->resize(
    $image, 
    // target size
    new Box(100, 200),
    // crop around the point at 50% to the right and 70% to the top
    new FocalPoint(0.5, 0.7),  
    // Imagine filter for resize (optional)
    ImageInterface::FILTER_UNDEFINED 
);

// maybe do further processing with the image...

$image->save('dragonfly-resized.jpg');

##How it works##

The cropping strategy used here is very simple. It just compares the width and height ratios of the original and target sizes. The focal point will be on the center of the crop on the axis on which the ratio is greater while the other axis will remain uncropped. If a part of the crop area goes beyond the image's edge it will be moved accordingly.

##Contribution##

I know there are other cropping strategies and some fit certain scenarios better than the others. Please suggest other (better) ways to do this. The logic could then be extracted to several strategy classes and let the user decide which one to use.

统计信息

  • 总下载量: 9.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固