PictureConverter

Created: 2012-03-26 06:40
Updated: 2014-01-31 08:06
php

README.md

PictureConverter

Convert image files

We can convert uploaded image files easily and quickly. I use it in my project made by CakePHP. It maybe can use on other PHP Framework.

Install

for CakePHP 2.x

  1. put /app/Controller/Component/PictureConverterComponent.php
  2. add 'PictureConverter' to $components

Usage

This sample for CakePHP 2.x

class User extends AppModel {
....

  public function setImage($filename) {

    $pathinfo = pathinfo($filename);

    $option = array(
      'Thumb' => array(
        'width' => 100, 'height' => 100,
        'align' => 'center', 'valign' => 'middle',
        'quality' => 100, 'background' => array('r' => 240, 'g' => 240, 'b' => 240),
        'file' => $pathinfo['dirname'].'/thumb_'.$pathinfo['basename'],
      )
    );

    $this->PictureConverter->Frame($filename, $option['Thumb']);
  }

....

}

Methods

  • Deform($src_file, $options) - Deform the image file to shape you want.
  • Scale($src_file, $options) - Change image size keep ratio (width or height larger).
  • Frame($src_file, $options) - Containment imagefile size by Frame. You can set filled background (image or color[ r, g, b ]).
  • Trim($src_file, $options) - Triming image by top, left, width, height.
  • Text($src_file, $options) - not yet.
  • Rotate($src_file, $options) - Rotate imagefile.

Options

  • top - Vertical Position (for Trim only)
  • left - Horizonal Position (for Trim obly)
  • width - width on output
  • height - height on output
  • quality - Jpeg quality [ 0 - 100 ]
  • degree - degree (for rotate only)
  • background - background color or background image filename.
  • align - image align on background [ left | center | right ]
  • valign - image valign on background [ top | center | bottom ]
  • file - output filename

Goal

  • Implement Text method.
  • Implement Border method.
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more