ripaclub/imgman 问题修复 & 功能扩展

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

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

ripaclub/imgman

Composer 安装命令:

composer require ripaclub/imgman

包简介

A library designed to create, modify, handle, and store images from any protocol

README 文档

README

Latest Stable Version Build Status Coverage Status

ImgMan is a library that allows you to create various image renditions from any PHP supported URL-style protocol containing a picture.

You can modify an image (e.g., resize, crop, format, fit in, fit out, rotate) and save different renditions stored in your configuration.

Requisites

  • PHP >= 5.5

  • Composer

  • Imagick (the only adapter currently supported to manipulate image)

Features

ImgMan has various features:

  • Core

    contains the engine that execute the operations on the image. ImageMagick is the only adapter present.

  • Operation

    Contains a class, HelperPluginManager, that is a AbstractPluginManager where are config all operation that can attach to a rendition (i.e. Compression, Crop, FitIn, FitOut, Format, Resize, Rotate,ScaleToHeight,ScaleToWidth)

  • Storage

    ImgMan allows you to save the image in several layers persistence, via StorageInterface objects (i.e. FileSystem, Mongo)

  • Image

    Contains the class used to the image

  • Service

    A set of classes aimed at the instantiation of ImgMan service. With this service you can save the image in all renditions configured in the service (grab function) You can also save update, and delete an image in a specific redition

Installation

Install ImageImagick (version > 3.1.2) in php extension.

Add ripaclub/imgman to your composer.json.

{
   "require": {
       "ripaclub/imgman": "0.5.*"
   }
}

Configuration

Configure service manager with service factory (for storage and service), plugin manager and imagick adapter.

return [
    \\ ...
    'abstract_factories' => [
         // Load abstract service
        'ImgMan\Service\ImageServiceAbstractFactory',
         // Load abstract factory for mongo storage
        'ImgMan\Storage\Adapter\Mongo\MongoDbAbstractServiceFactory',
        'ImgMan\Storage\Adapter\Mongo\MongoAdapterAbstractServiceFactory',
         // Load abstract factory to FileSystem storage
        'ImgMan\Storage\Adapter\FileSystem\FileSystemAbstractServiceFactory'
          // Load abstract factory to aws storage previus import of aws/aws-sdk-php 3.17.6
        'ImgMan\Storage\Adapter\Cdn\Amazon\S3\S3ServiceAbstractFactory',
        'ImgMan\Storage\Adapter\Cdn\Amazon\CloudFront\CloudFrontServiceAbstractFactory',
        'ImgMan\Storage\Adapter\Cdn\AmazonAdapterAbstractFactory',
    ],
    'factories' => [
         // Load (operation) helper plugin manager
        'ImgMan\Operation\HelperPluginManager' => 'ImgMan\Operation\HelperPluginManagerFactory',
    ],
    'invokables' => [
         // Load adapter
        'ImgMan\Adapter\Imagick' => 'ImgMan\Core\Adapter\ImagickAdapter',
        'ImgMan\ResolverDefault' => 'ImgMan\Storage\Adapter\FileSystem\Resolver\ResolverDefault'
    ],
    \\ ...
    
];

You can set only one storage configuration. Configure storage (e.g Mongo) where to save the images:

return [
    \\ ...
    'imgman_mongodb' => [
        'MongoDb' => [
            'database' => 'imgManStorage'
        ]
    ],
    'imgman_adapter_mongo' => [
        'Storage' => [
            'collection' => 'image_test',
            'database' => 'MongoDb'
        ]
    ],
    \\ ...
 ];

E.g aws configuration:

return [
    \\ ...
       'imgman_amazon_client' => [
           'AmazonS3Client' => [
               'secret' => 'testSecret',
               'key' => 'testKey',
               'region' => 'testRegion',
               'version' => 'latest',
               'name' => 'S3'
           ],
           'AmazonCloudFrontClient' => [
               'secret' => 'testSecret',
               'key' => 'testKey',
               'region' => 'testRegion',
               'version' => 'latest',
               'name' => 'CloudFront'
           ]
       ],
       'imgman_amazon_s3_service' => [
           'S3Service' => [
               'client' => 'AmazonS3Client',
               'bucket' => 'test'
           ]
       ],
       'imgman_amazon_cloud_front_service' => [
           'CloudFrontService' => [
               'client' => 'AmazonCloudFrontClient',
               'domain' => 'testdomain'
           ]
       ],
       'imgman_amazon_adapter' => [
           'Storage' => [
               's3_client' => 'S3Service',
               'cloud_front_client' => 'CloudFrontService',
               'name_strategy' => 'default',
               'name_strategy_config' => [
                   'prefix' => 'test'
               ]
           ]
       ]
    \\ ...
 ];

E.g filesystem configuration:

return [
    \\ ...
        'imgman_adapter_filesystem' => [
            'Storage' => [
                'path' => DIR_PATH_,
                'resolver' => 'ImgMan\ResolverDefault'
            ],
        ]
    \\ ...
 ];

Configure ImgMan service with the storage, helper, adapter and the various operations to attach on the renditions:

return [
    \\ ...
    'imgman_services' => [
        'ImgMan\Service\First' => [
            'adapter' => 'ImgMan\Adapter\Imagick',
            'storage' => 'Storage',
            'helper_manager' => 'ImgMan\Operation\HelperPluginManager',
            'renditions' => [
                'thumb' => [
                    'resize' => [
                        'width'  => 200,
                        'height' => 200,
                    ],
                    'compression' => [
                        'compression' => 90,
                        'compressionQuality' => 70,
                    ]
                ],
                'thumbmaxi' => [
                    'resize' => [
                        'width'  => 400,
                        'height' => 400,
                    ],
                ],
            ],
        ],
    ],
    \\ ...
 ];

Usage

Now we get the IgmMan service, load a picture from file stream (filesystem) and save it in 3 renditions (original, thumb, and thumbmaxi).

$imgMan = $this->getServiceLocator()->get('ImgMan\Service\First');
$image = new ImgMan\Image\Image(__DIR__. '/../../../name_image.png'); //the path can be also a URL
$imgMan->grab($image, '/first/name/identifier/');

Finally, we can recover the image rendition we desire this way:

$imageOriginal = $imgMan->get('/first/name/identifier/', 'original');
$imageThumb = $imgMan->get('/first/name/identifier/', 'thumb');
$imageThumbMaxi = $imgMan->get('/first/name/identifier/', 'thumbmaxi');

Analytics

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2014-08-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固