diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-03-09 11:44:54 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-03-09 11:44:54 +0000 |
commit | 0ea653502c6bbe09ba90d9aba0dce69b9ca1291f (patch) | |
tree | 20d6918349bd4938e2cf972fa73e012ebf3f46ee /modules/simpletest/tests/image_test.module | |
parent | 3faf46dcb0d092d735d6dafaa3760bf4f7826350 (diff) | |
download | brdo-0ea653502c6bbe09ba90d9aba0dce69b9ca1291f.tar.gz brdo-0ea653502c6bbe09ba90d9aba0dce69b9ca1291f.tar.bz2 |
- Patch #373613 by quicksketch and drewish: in order to operate on images multiple
times (such as crop, scale, then desaturate) without quality loss, we need to
pass images by their raw GD (or other library) resources rather than re-opening
the same image repeatedly, which causes wasted processing and loss of quality when
using JPEG images. This patch reworks the image toolkits, adds some new image
manipulations and adds some impressive SimpleTests.
Diffstat (limited to 'modules/simpletest/tests/image_test.module')
-rw-r--r-- | modules/simpletest/tests/image_test.module | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/modules/simpletest/tests/image_test.module b/modules/simpletest/tests/image_test.module new file mode 100644 index 000000000..07f59461d --- /dev/null +++ b/modules/simpletest/tests/image_test.module @@ -0,0 +1,121 @@ +<?php +// $Id$ + +/** + * @file + * Helper module for the image tests. + */ + +/** + * Implementation of hook_image_toolkits(). + */ +function image_test_image_toolkits() { + return array( + 'test' => array( + 'title' => t('A dummy toolkit that works'), + 'available' => TRUE, + ), + 'broken' => array( + 'title' => t('A dummy toolkit that is "broken"'), + 'available' => FALSE, + ), + ); +} + +/** + * Reset/initialize the history of calls to the toolkit functions. + * + * @see image_test_get_all_calls(). + */ +function image_test_reset() { + // Keep track of calls to these operations + $results = array( + 'load' => array(), + 'save' => array(), + 'settings' => array(), + 'resize' => array(), + 'crop' => array(), + 'desaturate' => array(), + ); + variable_set('image_test_results', $results); +} + +/** + * Get an array with the all the calls to the toolkits since image_test_reset() + * was called. + * + * @return + * An array keyed by operation name ('load', 'save', 'settings', 'resize', + * 'crop', 'desaturate') with values being arrays of parameters passed to + * each call. + */ +function image_test_get_all_calls() { + return variable_get('image_test_results', array()); +} + +/** + * Store the values passed to a toolkit call. + * + * @param $op + * One of the image toolkit operations: 'load', 'save', 'settings', 'resize', + * 'crop', 'desaturate'. + * @param $args + * Values passed to hook. + * @see image_test_get_all_calls() + * @see image_test_reset() + */ +function _image_test_log_call($op, $args) { + $results = variable_get('image_test_results', array()); + $results[$op][] = $args; + variable_set('image_test_results', $results); +} + +/** + * Image tookit's settings operation. + */ +function image_test_settings() { + _image_test_log_call('settings', array()); + return array(); +} + +/** + * Image tookit's load operation. + */ +function image_test_load(stdClass $image) { + _image_test_log_call('load', array($image)); + return $image; +} + +/** + * Image tookit's save operation. + */ +function image_test_save(stdClass $image, $destination) { + _image_test_log_call('save', array($image, $destination)); + // Return false so that image_save() doesn't try to chmod the destination + // file that we didn't bother to create. + return FALSE; +} + +/** + * Image tookit's crop operation. + */ +function image_test_crop(stdClass $image, $x, $y, $width, $height) { + _image_test_log_call('crop', array($image, $x, $y, $width, $height)); + return TRUE; +} + +/** + * Image tookit's resize operation. + */ +function image_test_resize(stdClass $image, $width, $height) { + _image_test_log_call('resize', array($image, $width, $height)); + return TRUE; +} + +/** + * Image tookit's desaturate operation. + */ +function image_test_desaturate(stdClass $image) { + _image_test_log_call('desaturate', array($image)); + return TRUE; +} |