Coder Social home page Coder Social logo

cakephp-imagetool-component's Introduction

CakePHP ImageTool Component

About

ImageTool is php class to perform various tasks with images. Every function accepts GD resource as input and can output it as well (just leave 'output' option empty).

Changes from 1.1.*

This library now consists purely from static functions as there was no need for class object. This makes it very easy to use in cake's models or anywhere else and isn't cakephp specific.

Installation

For use with cakephp:

  • Copy ImageTool.php to your app's Vendor/ directory
  • Include in your controller: App::import('Vendor', 'ImageTool');

For use as standalone library:

  • Include in your project with include() or similar method

Error handling

Most image processing functions return either true or false (depending if action was successfull). Only exception is when you don't specify output (or set it to null/empty) - in such cases (if action was successfull) GD resource is returned.

Available functions

  • autorotate - autorotate JPG images (by exif data)
  • averageColor - get image's average color
  • dominatingColor - get image's dominating color
  • flip - flip image
  • grayscale - desaturate image
  • meshify - add mesh (grid of dots) over image
  • pixelate - pixelate image
  • resize - resize image
  • rotate - rotate image (only degrees divisible by 90)
  • unsharpMask - sharpen image
  • watermark - add watermark

Examples

Make thumbnail 100x100px in size

$status = ImageTool::resize(array(
	'input' => $input_file,
	'output' => $output_file,
	'width' => 100,
	'height' => 100
));

Resize image (while keeping ratio) with max width and height both set to 600px. After that place watermark image in bottom-right corner and sharpen end result (with default settings)

$status = ImageTool::resize(array(
	'input' => $input_file,
	'output' => $output_file,
	'width' => 600,
	'height' => 600,
	'keepRatio' => true,
	'paddings' => false,
	'afterCallbacks' => array(
		array('watermark', array('watermark' => $watermark_file, 'position' => 'bottom-right')),
		array('unsharpMask'),
	)
));

Autorotate image (getting back GD resource and then passing it to the next function (greyscale) - similar to previous example but without using afterCallbacks option)

$image = ImageTool::autorotate(array(
	'input' => $input_file,
	'output' => null
));

if ($image) {
	$status = ImageTool::grayscale(array(
		'input' => $image,
		'output' => $output_file
	));
} else {
	$status = false;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.