polycast/polycast-filter-imagesize 问题修复 & 功能扩展

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

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

polycast/polycast-filter-imagesize

Composer 安装命令:

composer require polycast/polycast-filter-imagesize

包简介

Zend_Filter implementation for resizing images using different strategies.

README 文档

README

Zend Framework extension providing filter facilities for image size using different strategies.

Minimal example

<?php
require_once 'Polycast/Filter/ImageSize.php';
$filter = new Polycast_Filter_ImageSize();
$filter->getConfig()
    ->setHeight(100)
    ->setWidth(200);
$outputPath = $filter->filter('./orig.jpg');

header('Content-Type: image/jpeg');
$fh = fopen($outputPath, 'r');
fpassthru($fh);
fclose($fh);
?>

Complex example

  • Crop the image instead of fit it into the bounding box.
  • Output as JPEG (actually this is the same as above as it is the default)
  • Set a specific output directory (default = ./)
  • Use caching, i.e. override only if source image is newer than thumbnail (if exists)

[markdown syntax is stupid]

<?php
require_once 'Polycast/Filter/ImageSize.php';
require_once 'Polycast/Filter/ImageSize/Strategy/Crop.php';
require_once 'Polycast/Filter/ImageSize/PathBuilder/Standard.php';

$filter = new Polycast_Filter_ImageSize();

$filter->setOutputPathBuilder(
        new Polycast_Filter_ImageSize_PathBuilder_Standard('images/thumbnails'));

$filter->getConfig()
       ->setHeight(100)
       ->setWidth(200)
       ->setQuality(75)
       ->setOverwriteMode(Polycast_Filter_ImageSize::OVERWRITE_ALL)
       ->setOutputImageType(Polycast_Filter_ImageSize::TYPE_JPEG)
       ->setStrategy(new Polycast_Filter_ImageSize_Strategy_Crop());

$output = $filter->filter('./orig.jpg');

header('Content-Type: image/jpeg');
$fh = fopen($output, 'r');
fpassthru($fh);
fclose($fh);
?>

Humongous example

class NamedConfig extends Polycast_Filter_ImageSize_Configuration_Standard
{
    protected $_templateName = null;

    public function __construct($templateName)
    {
        $this->_templateName = $templateName;
    }

    public function getTemplateName()
    {
        return $this->_templateName;
    }
}

class CustomPathBuilder implements Polycast_Filter_ImageSize_PathBuilder_Interface
{
    private $_outputDir = null;

    public function __construct($outputDir) 
    {
        $this->_outputDir = $outputDir;
    }

    public function buildPath($filename, Polycast_Filter_ImageSize_Configuration_Interface $config) 
    {
        $chunks = explode('.', strrev(basename($filename)), 2);
        $basename = strrev(array_pop($chunks));
        $ext = strrev(array_pop($chunks));

        switch($config->getOutputImageType()) {

            case 'jpeg': $ext = '.jpg'; break;
            case 'gif': $ext = '.gif'; break;
            case 'png': $ext = '.png'; break;

            case 'auto':
            case null:
            default:
                $ext = ".$ext";
        } 

        if ($config instanceof NamedConfig) {
            $postfix = $config->getTemplateName();
        } else {
            $postfix = sprintf('%sx%s-q%s', $config->getWidth(), $config->getHeight(), $config->getQuality());
        }

        $path = sprintf('%s/%s-%s%s',
            $this->_outputDir,
            $basename,
            $postfix,
            $ext
        );

        return $path;
    }
}

$filter = new Polycast_Filter_ImageSize(); 
$config = $filter->getConfig();

$config = new NamedConfig('product-thumbnail-100x100');
$config
       ->setWidth(100)
       ->setHeight(100)
       ->setQuality(50)
       ->setStrategy(new Polycast_Filter_ImageSize_Strategy_Crop())
       ->setOverwriteMode(Polycast_Filter_ImageSize::OVERWRITE_ALL)
; 

$filter->setConfig($config);
$filter->setOutputPathBuilder(new CustomPathBuilder('images/thumbnails/')); 
$outputPath = $filter->filter('./rick.jpg'); 

More examples

Have a look at the tests/ExamplesTest.php which demonstrates how to implement own path builders and configurations.

Installation

composer

If you want to use this library in your project, adjust your composer.json like this:

"require": {
    "polycast/polycast-filter-imagesize": "master-dev"
},

If you want to work on this library use the following command, which will checkout the project from github and install all dependencies needed for development.

composer create-project --dev polycast/polycast-filter-imagesize polycast-filter-imagesize

polycast/polycast-filter-imagesize 适用场景与选型建议

polycast/polycast-filter-imagesize 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.95k 次下载、GitHub Stars 达 22, 最近一次更新时间为 2012 年 11 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「image」 「filter」 「ZF1」 「resizing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 polycast/polycast-filter-imagesize 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 polycast/polycast-filter-imagesize 我们能提供哪些服务?
定制开发 / 二次开发

基于 polycast/polycast-filter-imagesize 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.95k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 22
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-11-11