Skip to content

apoca/WebinoImageThumb

 
 

Repository files navigation

Image Thumbnailer
for Zend Framework 2

Build Status Coverage Status Dependency Status Build Status Coverage Status Dependency Status

Latest Stable Version Latest Unstable Version Scrutinizer Quality Score Daily Downloads Montly Downloads Total Downloads

Service that provides API to manipulate images.

Powered by PHPThumb

Features

  • Resize, crop, pad, rotate, show and save images
  • Create image reflection
  • Crop whitespace

Setup

Following steps are necessary to get this module working, considering a zf2-skeleton or very similar application:

  1. Run: php composer.phar require webino/webino-image-thumb:2.*
  2. Add WebinoImageThumb to the enabled modules list

Requirements

  • GD 2.0+

QuickStart

  • For example add following code into the controller action, assume example image:

    // We encourage to use Dependency Injection instead of Service Locator
    $thumbnailer = $this->getServiceLocator()->get('WebinoImageThumb');
    $imagePath   = 'public/images/example.jpg';
    $thumb       = $thumbnailer->create($imagePath, $options = array(), $plugins = array());
    
    $thumb->resize(100, 100);
    
    $thumb->show();
    // or/and
    $thumb->save('public/images/resized.jpg');
    

    NOTE: If you don't know how to inject the WebinoImageThumb into action controller, check out test/resources

  • Use reflection plugin:

    $reflection = $thumbnailer->createReflection(40, 40, 80, true, '#a4a4a4');
    $thumb      = $thumbnailer->create($imagePath, array(), array($reflection));
    
  • Use whitespace cropper plugin:

    $cropper = $thumbnailer->createWhitespaceCropper();
    $thumb   = $thumbnailer->create($imagePath, array(), array($cropper));
    

Options

The options array allows you to customize the behavior of the library a bit. Some of these options are implementation-specific, and are noted as such. So, let's first go over what options are available to us:

Option Name Description Default Value Valid Values
resizeUp Whether or not to scale an image up to the desired dimensions false true / false
jpegQuality What quality to save jpeg files with (how much compression to use, 100 being none) 100 1-100
correctPermissions Whether or not the library should attempt to correct file permissions. This will only work if you set up your PHP to allow chmod operations false true / false
preserveAlpha Whether or not to preserve alpha transparency in PNG files true true / false
alphaMaskColor What rgb color should be used for the alpha mask array(255,255,255) array([0-255], [0-255], [0-255])
preserveTransparency Whether or not to preserve transparency in GIF files true true / false
transparencyMaskColor What rgb color should be used for the transparency mask array(255,255,255) array([0-255], [0-255], [0-255])
interlace When the interlace option equals true or false call imageinterlace null true / false

Functions

  • adaptiveResize($width, $height)
  • adaptiveResizePercent($width, $height, $percent = 50)
  • adaptiveResizeQuadrant($width, $height, $quadrant = 'T|B|C|L|R')
  • crop($startX, $startY, $cropWidth, $cropHeight)
  • cropFromCenter($cropWidth, $cropHeight = null)
  • pad($width, $height, $color = array(255, 255, 255))
  • resize($maxWidth, $maxHeight)
  • resizePercent($percent)
  • rotateImage($direction = 'CW|CCW')
  • rotateImageNDegrees($degrees)
  • save($fileName, $format = 'GIF|JPG|PNG')
  • show($rawData = false)

Getters / Setters

  • getCurrentDimensions()
  • getFileName()
  • getFormat()
  • getIsRemoteImage()
  • getMaxHeight()
  • getMaxWidth()
  • getNewDimensions()
  • getOldImage()
  • getOptions()
  • getPercent()
  • getWorkingImage()
  • setCurrentDimensions($currentDimensions)
  • setFileName($fileName)
  • setFormat($format)
  • setMaxHeight($maxHeight)
  • setMaxWidth($maxWidth)
  • setNewDimensions($newDimensions)
  • setOldImage($oldImage)
  • setOptions($options)
  • setPercent($percent)
  • setWorkingImage($workingImage)

Reflection plugin

  • createReflection($percent, $reflection, $white, $border, $borderColor)

    • $percent - What percentage of the image to create the reflection from.
    • $reflection - What percentage of the image height should the reflection height be.
    • $white - How transparent (using white as the background) the reflection should be, as a percent.
    • $border - Whether a border should be drawn around the original image.
    • $borderColor - The hex value of the color you would like your border to be.

Whitespace Cropper plugin

  • createWhitespaceCropper($border, $color)

    • $margin - What pixels of a margin should be around the original image.
    • $color - The hex value of the color you would like to crop.

Changelog

2.0.0

  • Requires PHPThumb 2.0 via composer
  • Added Whitespace Cropper plugin

1.0.0

  • Initial release

Develop

This package uses Grunt task runner to automating the development.

Requirements

Setup

Setting up development environment of the package.

  1. Clone this repository and run: npm install

  2. To update development environment run: grunt update

    Now your development environment is set.

  3. Open project in (NetBeans) IDE

  4. To check module integration with the skeleton application open following directory via web browser: ._test/ZendSkeletonApplication/public/

    e.g. http://localhost/webino/WebinoImageThumb/._test/ZendSkeletonApplication/public/

  5. Integration test resources are in directory: test/resources

Testing

  • Run phpunit in the test directory

  • Run grunt test in the module directory to run tests and code analysis

    NOTE: To run the code analysis there are some tool requirements:

    NOTE: Those tools are present after development environment is based.

  • Run grunt selenium_test in the module directory to run the Selenium WebDriver tests

    NOTE: To specify the testing URI set the uri option, e.g. grunt selenium_test -uri http://example.com/

    NOTE: Selenium server will be started/stopped automatically, assuming /etc/init.d/selenium is available to run.

Addendum

Most of the documentation is taken from the PHPThumb wiki.

Please, if you are interested in this Zend Framework module report any issues and don't hesitate to contribute.

Report a bug | Fork me

About

Image Thumbnailer for Zend Framework 2

Resources

License

Stars

Watchers

Forks

Packages

No packages published