2017 © Pedro Peláez
 

library yii2-imageprocessor

Configurable image processing for Yii2

image

phtamas/yii2-imageprocessor

Configurable image processing for Yii2

  • Sunday, April 19, 2015
  • by phtamas
  • Repository
  • 1 Watchers
  • 4 Stars
  • 701 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 10 Open issues
  • 5 Versions
  • 22 % Grown

The README.md

yii2-imageprocessor

Application component for Yii2. Its main use case is to process images with a chain of preconfigured transformations. A simple DSL inspired by WideImage's smart coordinates is used to add some flexibility to the configuration. WideImage library itself isn't used, all actual image processing is delegated to Imagine., (*1)

Ad-hoc processing is also supported but if heavy and complex image manipulation is a key feature of your application it's probably better to use Imagine directly., (*2)

Getting started

Install via Composer:, (*3)

    "require": {
        "phtamas/yii2-imageprocessor": "0.5.*"
    }

Configure it in the 'components' section of your application configuration:, (*4)

'imageProcessor' => [
  'class' => '\phtamas\yii2\imageprocessor\Component',
  // Default for all JPEG images
  'jpegQuality' => 90,
  // Default for all PNG images
  'pngCompression' => 7,

  // Create named image categories with their own configuration.
  // You can refer them by name in application code.
  'define' => [

    'userAvatar' => [
      // Add transformations. They will be applied in the order they were defined.
      'process' => [
        // Fix images with embedded orientation metadata
        ['autorotate'],
        // Preapre image to crop by resizing it to cover a 160*160 square
        ['resize', 'width' => 160, 'height' => 160, 'scaleTo' => 'cover'],
        // Crop it
        ['crop', 'x' => 'center - 80', 'y' => 'center - 80', 'width' => 160, 'height' => 160],
      ],
    ],

    'galleryImage' => [
       // Override default to save some disk space and bandwidth
      'jpegQuality' => 80,
      'process' => [
        // Resize proportionally to fit a 600*600 square but only if too large
        ['resize', 'width' => 600, 'height' => 600, 'scaleTo' => 'fit', 'only' => 'down'],
        // Mark your property
        ['watermark', 'path' => '@path/to/wmark.png', 'align' => 'top-left', 'margin' => 20],
      ],
    ],

  ],
],

And use it anywhere in your application:, (*5)

// Process uploaded image and save as a JPEG file
$path = '@image/user/avatar/' . uniqid() . '.jpg';
Yii::$app->imageProcessor->save(['file' => $uploadedFile->tempName], $path, 'userAvatar');

// Process image (stored as BLOB in the DB) and send it to the HTTP client
Yii::$app->imageProcessor->send(['data' => 'binary string'], 'jpg', 'galleryImage');

// Ad-hoc processing is possible, too
Yii::$app->imageProcessor->saveAndSend(['file' => '@images/image.jpg'], $path, 'jpg', [
    'process' => [['resize', 'width' => 300]], // Resize proportionally to 300 px width
]);

Learn more

The Versions

19/04 2015

0.6.0.x-dev

0.6.0.9999999-dev

Configurable image processing for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Papp-Horváth Tamás

yii2 image manipulation image processing image transformation

05/03 2015

dev-master

9999999-dev

Configurable image processing for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Papp-Horváth Tamás

yii2 image manipulation image processing image transformation

05/03 2015

v0.5.1

0.5.1.0

Configurable image processing for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Papp-Horváth Tamás

yii2 image manipulation image processing image transformation

03/03 2015

v0.5.0

0.5.0.0

Configurable image processing for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Papp-Horváth Tamás

yii2 image manipulation image processing image transformation

23/02 2015

v0.5.0-beta

0.5.0.0-beta

Configurable image processing for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Papp-Horváth Tamás

yii2 image manipulation image processing image transformation