- ⌂ io_comand_image
- Classes
Image Processing API
io_comand_image
The COMAND Image Processing API is used to programmatically process and manipulate images from cTemplate, cScript and PHP code.
Image Data Type Fields (image_holder)
Images referenced from Image Data fields of a cObject utilize the image_holder class, which encapsulates the image as a simple binary string, which can be efficiently read and written without further processing. However, an image_holder will automatically convert the image to and from ImageData objects when referenced like one. For example, $object->Image->resize()
will automatically convert the Image field data to an ImageData object in order to resize it. Once the additional memory consumed by the ImageData object is needed for other purposes, it will automatically be converted back to a simple binary string to release the additional memory overhead of the ImageData object. Subsequent operations will automatically convert it back again if necessary.
cTemplate & cScript
The COMAND Image Processing API is utilized internally by #IMAGE().
Configuration
The image processing API generally does not need to be configured because the default configuration will automatically detect and use ImageMagick when installed, otherwise fallback to GD. However, ImageMagick or GD can be manually configured in the main config.php with one of the following options.
'io_comand_image' => ['image_library' =>'auto']
- If neither ImageMagick or GD is available, exceptions will be thrown (default).'io_comand_image' => ['image_library' =>'imagick']
- Always use ImageMagick. If not available, exceptions will be thrown.'io_comand_image' => ['image_library' =>'gd']
- Always use GD. If not available, exceptions will be thrown.
Classes
A single entry point class is used to access all of the Image Processing API functionality.
Example
// Load the webCOMAND logo image (SVG)
$url = 'https://www.webcomand.com/img/webcomand-logo.svg';
$svg = get_file_contents($url);
$image = new \io_comand_image\models\ImageData($svg);
// Resize the image proportionally to 320 pixels wide
$image->resize(320, 0);
// Change the image format to PNG
$image->set_format('PNG');
// Write the PNG image to the file system
file_put_contents('logo.png', $image);