$_filename
$_filename : string
The file currently being processed.
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.
__construct(\midcom_db_attachment $input = null)
\midcom_db_attachment | $input |
write(\midcom_db_attachment $target)
\midcom_db_attachment | $target |
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.
string | $filename | The file to be edited. |
true, if the file is valid, false otherwise.
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.
string | $chain | The filter chain to be processed (filter1();filter2();...) |
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.
string | $format | The format to convert to. This must be a valid conversion targed recognized by Imagemagick, it defaults to 'jpg'. |
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.
integer | $x | Width |
integer | $y | Height |
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
integer | $x | Width |
$gravity |
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.
string | $cmd | The command to be executed. |
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.
string | $command | The name of the callback to execute |
array | $args | The arguments passed to the callback |