\midcom_helper_imagefilter

Image Filter Class, used to post process all images, check the documentation of the individual methods.

This class always works on existing files at this time. It supports scripting support by using the process_chain / process_command helper functions, which allow the application to let the user specify a list of filters that should be applied during upload.

Summary

Methods
Properties
Constants
__construct()
__destruct()
create_tmp_copy()
write()
imagemagick_available()
set_file()
get_file()
process_chain()
gamma()
convert()
identify()
exifrotate()
rotate()
resize()
squarethumb()
crop()
fill()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
_jpegtran_available()
process_command()
_run_command()
_get_tempfile()
_process_tempfile()
execute_user_callback()
$_filename
$_quality
$_tmpfiles
N/A

Properties

$_filename

$_filename : string

The file currently being processed.

Type

string

$_quality

$_quality : string

The quality to use for JPEG manipulation, this is not yet settable from the outside.

Stored as a valid imagemagick option, defaults to '-quality 90' right now.

Type

string

$_tmpfiles

$_tmpfiles : array

Tmpfiles used by this instance

Type

array

Methods

__destruct()

__destruct() 

create_tmp_copy()

create_tmp_copy(mixed  $input) : string

Creates a working copy to filesystem from given attachment object

Parameters

mixed $input

The attachment object or filename to copy

Returns

string —

tmp file name (or false on failure)

imagemagick_available()

imagemagick_available() 

set_file()

set_file(string  $filename) : boolean

Sets the filename of the image currently being edited.

This must be the full path to the file, it will be replaced with the modified image.

The process will check for write permissions at this point, A return value of false will indicate some problem, see the debug log for details.

Parameters

string $filename

The file to be edited.

Returns

boolean —

true, if the file is valid, false otherwise.

get_file()

get_file() : string

Get the filename

Returns

string

process_chain()

process_chain(string  $chain) 

Process a string-based filter chain.

This is a semicolon-separated list of commands, which will be evaluated using process_command each.

Processing stops as soon as one filter command fails.

Parameters

string $chain

The filter chain to be processed (filter1();filter2();...)

gamma()

gamma(float  $gamma = 1.2) 

Gamma-Adjustment of the image.

Filter Syntax: gamma($gamma)

Where $gamma is a positive floating point number, e.g. 1.2

Parameters

float $gamma

Gamma adjustment value.

convert()

convert(string  $format = 'jpg') 

Convert the image to the specified image format.

It must be a suitable extension to use with the Imagemagick convert utility. The file will not be renamed, you have to do this yourself.

This call will always convert the first page only of the supplied image, otherwise, Imagemagick would spam the temp directory in case we are working on a PDF file or whatever.

Parameters

string $format

The format to convert to. This must be a valid conversion targed recognized by Imagemagick, it defaults to 'jpg'.

identify()

identify(  $filename) 

Parameters

$filename

exifrotate()

exifrotate() 

Automatic rotation for the image using EXIF tags.

NOTE: This REQUIRES php_read_exif to be present. It will fail if it is missing.

Filter Syntax: exifrotate()

rotate()

rotate(float  $rotate) 

Manual image rotation

Filter Syntax: rotate($rotate)

Where $rotate is a positive floating point number greater than 0 and less than 360; if omitted, a null operation is done.

Parameters

float $rotate

Degrees of rotation clockwise, negative amounts possible

resize()

resize(integer  $x, integer  $y) 

Image Resize: This will resize the original image.

Filter Syntax: resize ($x, $y)

The width of the image in pixels, it will be scaled in proportion. One of the two parameters can be 0, meaning that the width/height of the image is adjusted to the other, given value.

The resize will be done only if it would not increase the image as this won't gain you any benefit.

Parameters

integer $x

Width

integer $y

Height

squarethumb()

squarethumb(integer  $x,   $gravity = 'center') 

Square Thumbnails: This will resize&crop the original image.

Filter Syntax: squarethumb ($x)

The filter will adapt picture to given width, point gravity to the centre and crop leftovers.

This is a one parameter shorthand for cropping, provided for backwards compatibility

Parameters

integer $x

Width

$gravity

crop()

crop(integer  $x, integer  $y,   $gravity = 'center') 

Crop an image to given proportions

Parameters

integer $x

Width

integer $y

Height

$gravity

fill()

fill(integer  $x = null, integer  $y = null, string  $color = null, string  $gravity = 'center') 

Resize image and apply fill to match given size

Parameters

integer $x

Width

integer $y

Height

string $color

Color

string $gravity

Gravity point

_jpegtran_available()

_jpegtran_available() 

process_command()

process_command(string  $cmd) 

This is the main function evaluator of the filter class.

It will take a function style command like resize(90,90), arguments are separated by commas, there is no quoting at the moment. All arguments are parsed as strings, function names need to be [a-z_]

Execution will relay to the corresponding filter function.

All filters will use defaults for missing arguments (which can result in a null operation) and will ignore excessive arguments.

Parameters

string $cmd

The command to be executed.

_run_command()

_run_command(  $cmd,   $tempfile = null) 

Parameters

$cmd
$tempfile

_get_tempfile()

_get_tempfile() 

Returns the name of a temporary file to be used to write the transformed image to. Has to be managed by the callee.

_process_tempfile()

_process_tempfile(  $tmpname) 

This will replace the original file with the processed copy of $tmpfile, deleting the temporary file afterwards.

Parameters

$tmpname

execute_user_callback()

execute_user_callback(string  $command, array  $args) 

Executes a custom image manipulation callback.

The command name is the function that is searched. The function must use the following signature:

boolean callback (string $infile, string $outfile, array $parameters);

infile is the file to be manipulated, outfile the name where the result has to be stored in (a temporary file usually) and the parameters passed to the command originally. It should return true on a successful transformation, false otherwise.

Parameters

string $command

The name of the callback to execute

array $args

The arguments passed to the callback