stefano/stefano-image

Image processing

Installs: 15

Dependents: 0

Stars: 1

Watchers: 1

Language: PHP

0.1.0 2014-01-19 21:13 UTC

README

Test Status Code Coverage Dependencies 68747470733a2f2f7365637572652e7472617669 Coverage Status Dependency Status

Features

  • Resize and save image
  • Add watermark
  • Supported input and output format jpg, png, gif

Dependencies

  • php GD2 extension

Instalation using Composer

  1. Add following line to composer.json "stefano/stefano-image": "*"

Usage

This is the original image

source.jpeg

  • resize and keep source image aspect ration
$maxWidth = 200;
$maxHeight = 200;
$resizer = new \StefanoImage\Image();
$resizer->sourceImage($sourceImage)
        ->resize($maxWidth, $maxHeight)
        ->save($outputDir, $name);

This is the output

resize.jpeg

  • adaptive resize
$width = 200;
$height = 50;
$resizer = new \StefanoImage\Image();
$resizer->sourceImage($sourceImage)
        ->adaptiveResize($width, $height)
        ->save($outputDir, $name);

This is the output

adaptive-resize.jpeg

  • pad
$width = 200;
$height = 200;
$resizer = new \StefanoImage\Image();
$resizer->sourceImage($sourceImage)
        ->pad($width, $height)
        ->save($outputDir, $name);

This is the output

pad.jpeg

  • pad and change background color
$width = 350;
$height = 150;
$resizer = new \StefanoImage\Image();
$resizer->sourceImage($sourceImage)
        ->pad($width, $height)
        ->backgroundColor(35, 210, 240)
        ->save($outputDir, $name);

This is the output

pad-2.jpeg

  • add watermark
$maxWidth = 350;
$maxHeight = 150;
$maxWidthPercent = 40;
$maxHeightPercent = 40;
$opacity = 30;
$watermarkPosition = \StefanoImage\Image::WATERMARK_POSITION_TOP_RIGHT;
$resizer = new \StefanoImage\Image();
$resizer->sourceImage($sourceImage)
        ->resize($maxWidth, $maxHeight)
        ->addWatermark($watermark, $maxWidthPercent, $maxHeightPercent, $opacity, $watermarkPosition)
        ->save($outputDir, $name);

This is the output

watermark.jpeg

  • change output format
$resizer->outputFormat(\StefanoImage\Image::OUTPUT_FORMAT_PNG);
  • change output quality
$resizer->quality(15);