summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--imagecache.module13
-rw-r--r--imagecache_actions.inc118
2 files changed, 22 insertions, 109 deletions
diff --git a/imagecache.module b/imagecache.module
index 289c3fe..485c583 100644
--- a/imagecache.module
+++ b/imagecache.module
@@ -331,7 +331,7 @@ function _imagecache_cache($presetname, $path) {
imagecache_transfer($dst);
}
-function _imagecache_apply_action($action, $image) {
+function _imagecache_apply_action($action, &$image) {
$actions = imagecache_action_definitions();
if ($definition = imagecache_action_definition($action['action'])) {
@@ -462,7 +462,7 @@ function imagecache_build_derivative($actions, $src, $dst) {
$action['data'][$key] = _imagecache_filter($key, $value, $image->info['width'], $image->info['height'], $width, $height);
}
}
- if (!$image = _imagecache_apply_action($action, $image)) {
+ if (!_imagecache_apply_action($action, $image)) {
watchdog( 'imagecache', t('action(id:%id): %action failed for %src', array('%id' => $action['actionid'], '%action' => $action['action'], '%src' => $src)), WATCHDOG_ERROR);
return FALSE;
}
@@ -508,8 +508,7 @@ function imagecache_field_formatter_info() {
* Implementation of hook_field_formatter().
*/
function imagecache_field_formatter($field, $item, $formatter) {
- if (empty($item['fid'])) {
- //drupal_set_message('imagecache_field_formatter: <pre>'. print_r($field, TRUE) .'</pre>');
+ if (empty($item['fid']) && $field['use_default_image']) {
$item = $field['default_image'];
}
// Views does not load the file for us, while CCK display fields does.
@@ -645,12 +644,12 @@ function theme_imagecache_imagelink($namespace, $path, $alt = '', $title = '', $
/************************************************************************************
* ImageCache action implementation example in module.
*/
-function imagecache_resize_image($image, $data) {
- if (!$image = imageapi_image_resize($image, $data['width'], $data['height'])) {
+function imagecache_resize_image(&$image, $data) {
+ if (!imageapi_image_resize($image, $data['width'], $data['height'])) {
watchdog('imagecache', t('imagecache_resize_image failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, TRUE))), WATCHDOG_ERROR);
return FALSE;
}
- return $image;
+ return TRUE;
}
function imagecache_resize_form($action) {
diff --git a/imagecache_actions.inc b/imagecache_actions.inc
index 62560da..1f0c996 100644
--- a/imagecache_actions.inc
+++ b/imagecache_actions.inc
@@ -21,15 +21,15 @@ function theme_imagecache_scale($element) {
return $output;
}
-function imagecache_scale_image($image, $data) {
+function imagecache_scale_image(&$image, $data) {
// Set impossibly large values if the width and height aren't set.
$data['width'] = $data['width'] ? $data['width'] : 9999999;
$data['height'] = $data['height'] ? $data['height'] : 9999999;
- if (!$image = imageapi_image_scale($image, $data['width'], $data['height'], $data['upscale'])) {
+ if (!imageapi_image_scale($image, $data['width'], $data['height'], $data['upscale'])) {
watchdog('imagecache', t('imagecache_scale_image failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, TRUE))), WATCHDOG_ERROR);
return FALSE;
}
- return $image;
+ return TRUE;
}
@@ -45,15 +45,15 @@ function theme_imagecache_scale_and_crop($element) {
}
-function imagecache_scale_and_crop_image($image, $data) {
+function imagecache_scale_and_crop_image(&$image, $data) {
// Set impossibly large values if the width and height aren't set.
$data['width'] = $data['width'] ? $data['width'] : 9999999;
$data['height'] = $data['height'] ? $data['height'] : 9999999;
- if (!$image = imageapi_image_scale_and_crop($image, $data['width'], $data['height'])) {
+ if (!imageapi_image_scale_and_crop($image, $data['width'], $data['height'])) {
watchdog('imagecache', t('imagecache_scale_and_crop failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, TRUE))), WATCHDOG_ERROR);
return FALSE;
}
- return $image;
+ return TRUE;
}
@@ -97,7 +97,7 @@ function theme_imagecache_deprecated_scale($element) {
return 'width: '. $data['width'] .', height: '. $data['height'] .', fit: '. $options[$data['fit']];
}
-function imagecache_deprecated_scale_image($image, $data) {
+function imagecache_deprecated_scale_image(&$image, $data) {
if ($data['fit'] == 'outside' && $data['width'] && $data['height']) {
$ratio = $image->info['width'] / $image->info['height'];
$new_ratio = $data['width']/$data['height'];
@@ -107,11 +107,11 @@ function imagecache_deprecated_scale_image($image, $data) {
// Set impossibly large values if the width and height aren't set.
$data['width'] = $data['width'] ? $data['width'] : 9999999;
$data['height'] = $data['height'] ? $data['height'] : 9999999;
- if (!$image = imageapi_image_scale($image, $data['width'], $data['height'])) {
+ if (!imageapi_image_scale($image, $data['width'], $data['height'])) {
watchdog('imagecache', t('imagecache_deprecated_scale failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, TRUE))), WATCHDOG_ERROR);
return FALSE;
}
- return $image;
+ return TRUE;
}
@@ -152,12 +152,12 @@ function theme_imagecache_crop($element) {
return 'width: '. $data['width'] .', height: '. $data['height'] .', xoffset: '. $data['xoffset'] .', yoffset: '. $data['yoffset'];
}
-function imagecache_crop_image($image, $data) {
- if (!$image = imageapi_image_crop($image, $data['xoffset'], $data['yoffset'], $data['width'], $data['height'])) {
+function imagecache_crop_image(&$image, $data) {
+ if (!imageapi_image_crop($image, $data['xoffset'], $data['yoffset'], $data['width'], $data['height'])) {
watchdog('imagecache', t('imagecache_crop failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, TRUE))), WATCHDOG_ERROR);
return FALSE;
}
- return $image;
+ return TRUE;
}
@@ -173,96 +173,10 @@ function theme_imagecache_desaturate($element) {
}
-function imagecache_desaturate_image($image, $data = array()) {
- if (!$image = imageapi_image_desaturate($image)) {
- watchdog('imagecache', t('imagecache_desaturate failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, TRUE))), WATCHDOG_ERROR);
+function imagecache_desaturate_image(&$image, $data = array()) {
+ if (!imageapi_image_desaturate($image)) {
+ watchdog('imagecache', t('imagecache_desaturate failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, TRUE))), WATCHDOG_ERROR);
return FALSE;
}
- return $image;
+ return TRUE;
}
-
-if (!function_exists('image_gd_desaturate')) {
- function image_gd_desaturate($source, $destination) {
- $info = image_get_info($source);
- if (!$info) {
- return FALSE;
- }
- $width = $info['width'];
- $height = $info['height'];
-
- $im = image_gd_open($source, $info['extension']);
-
- if (function_exists('imagefilter')) { // PHP 5
- if (!imagefilter($im, IMG_FILTER_GRAYSCALE)) {
- return FALSE;
- }
- $result = image_gd_close($im, $destination, $info['extension']);
- imageDestroy($im);
-
- } else { // PHP < 5
- $res = imageCreateTrueColor($width, $height);
-
- for ($y = 0; $y < $height; ++$y)
- for ($x = 0; $x < $width; ++$x) {
- $rgb = imagecolorat($im, $x, $y);
- if (imageistruecolor($im)) {
- $red = ($rgb >> 16) & 0xFF;
- $green = ($rgb >> 8) & 0xFF;
- $blue = $rgb & 0xFF;
- } else {
- $rgb = imagecolorsforindex($im, $rgb);
- $red = $rgb['red'];
- $green = $rgb['green'];
- $blue = $rgb['blue'];
- }
-
- $gray = round(.299*$red + .587*$green + .114*$blue);
-
- // shift gray level to the left
- $grayR = $gray << 16; // R: red
- $grayG = $gray << 8; // G: green
- $grayB = $gray; // B: blue
- $grayColor = $grayR | $grayG | $grayB;
-
- // set the pixel color
- imagesetpixel($res, $x, $y, $grayColor);
- imagecolorallocate($res, $gray, $gray, $gray);
- }
-
- $result = image_gd_close($res, $destination, $info['extension']);
-
- imageDestroy($res);
- imageDestroy($im);
- }
-
- return $result;
- }
-}
-
-if (!function_exists('image_scale_and_crop')) {
- /**
- * Scales an image to the given width and height by scaling and cropping.
- *
- * The resulting image always has the exact target dimensions.
- *
- * @param $source The file path of the source image
- * @param $destination The file path of the destination image
- * @param $width The target width
- * @param $height The target height
- *
- * @return True or FALSE, based on success
- */
- function image_scale_and_crop($source, $destination, $width, $height) {
- $info = image_get_info($source);
-
- $scale = max($width / $info['width'], $height / $info['height']);
- $x = round(($info['width'] * $scale - $width) / 2);
- $y = round(($info['height'] * $scale - $height) / 2);
-
- if (image_toolkit_invoke('resize', array($source, $destination, $info['width'] * $scale, $info['height'] * $scale))) {
- return image_toolkit_invoke('crop', array($destination, $destination, $x, $y, $width, $height));
- }
- }
-}
-
-