Viewing file: imagecache_actions.inc (8.42 KB) -rw-rw-rw- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php // $Id: imagecache_actions.inc,v 1.14 2008/05/30 16:25:06 dopry Exp $
/** * Imagecache Scale */ function imagecache_scale_form($data) { $form = imagecache_resize_form($data); $form['upscale'] = array( '#type' => 'checkbox', '#default_value' => (isset($data['upscale'])) ? $data['upscale'] : 0, '#title' => t('Allow Upscaling'), '#description' => t('Let scale make images larger than their original size'), ); return $form; }
function theme_imagecache_scale($element) { $output = theme_imagecache_resize($element) . ', upscale: '; $output .= ($element['#value']['upscale']) ? t('Yes') : t('No'); return $output; }
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 (!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 true; }
/** * Imagecache Scale and Crop */ function imagecache_scale_and_crop_form($data) { return imagecache_resize_form($data); }
function theme_imagecache_scale_and_crop($element) { return theme_imagecache_resize($element); }
function imagecache_scale_and_crop_image(&$image, $data) { 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 true; }
/** * Imagecache Deprecated Scale. * This will be removed in imagecache 2.1 */ function imagecache_deprecated_scale_form($data) { $helptext = array(); $helptext['inside'] = t('<strong>Inside dimensions</strong>: Final dimensions will be less than or equal to the entered width and height. Useful for ensuring a maximum height and/or width.'); $helptext['outside'] = t('<strong>Outside dimensions</strong>: Final dimensions will be greater than or equal to the entered width and height. Ideal for cropping the result to a square.'); $description = '<ul><li>'. implode('</li><li>', $helptext) .'</li><ul>';
$form['fit'] = array( '#type' => 'select', '#title' => t('Scale to fit'), '#options' => array('inside' => t('Inside dimensions'), 'outside' => t('Outside dimensions')), '#default_value' => $data['fit'], '#weight' => 1, '#description' => $description, ); $form['width'] = array( '#type' => 'textfield', '#title' => t('Width'), '#default_value' => $data['width'], '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'), ); $form['height'] = array( '#type' => 'textfield', '#title' => t('Height'), '#default_value' => $data['height'], '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'), ); return $form; }
function theme_imagecache_deprecated_scale($element) { $data = $element['#value']; $options = array('inside' => t('Inside dimensions'), 'outside' => t('Outside dimensions')); return 'width: '. $data['width'] .', height: '. $data['height'] .', fit: '. $options[$data['fit']]; }
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']; $data['width'] = $ratio > $new_ratio ? 0 : $data['width']; $data['height'] = $ratio < $new_ratio ? 0 : $data['height']; } // 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 (!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 true; }
/** * Imagecache Crop */ function imagecache_crop_form($data) { $data += array( 'width' => '', 'height' => '', 'xoffset' => '', 'yoffset' => '', ); $form['width'] = array( '#type' => 'textfield', '#title' => t('Width'), '#default_value' => $data['width'], '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'), ); $form['height'] = array( '#type' => 'textfield', '#title' => t('Height'), '#default_value' => $data['height'], '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'), ); $form['xoffset'] = array( '#type' => 'textfield', '#title' => t('X offset'), '#default_value' => $data['xoffset'], '#description' => t('Enter an offset in pixels or use a keyword: <em>left</em>, <em>center</em>, or <em>right</em>.'), ); $form['yoffset'] = array( '#type' => 'textfield', '#title' => t('Y offset'), '#default_value' => $data['yoffset'], '#description' => t('Enter an offset in pixels or use a keyword: <em>top</em>, <em>center</em>, or <em>bottom</em>.'), ); return $form; }
function theme_imagecache_crop($element) { $data = $element['#value']; return 'width: '. $data['width'] .', height: '. $data['height'] .', xoffset: '. $data['xoffset'] .', yoffset: '. $data['yoffset']; }
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 true; }
/** * Imagecache Desaturate */ function imagecache_desaturate_form($data) { return array(); }
function theme_imagecache_desaturate($element) { return ''; }
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 true; }
/** * Imagecache Rotate */ function imagecache_rotate_form($data) { $form['degrees'] = array( '#type' => 'textfield', '#default_value' => (isset($data['degrees'])) ? $data['degrees'] : 0, '#title' => t('Rotation angle'), '#description' => t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'), ); $form['random'] = array( '#type' => 'checkbox', '#default_value' => (isset($data['random'])) ? $data['random'] : 0, '#title' => t('Randomize'), '#description' => t('Randomize the rotation angle for each image. The angle specified above is used as a maximum.'), ); $form['bgcolor'] = array( '#type' => 'textfield', '#default_value' => (isset($data['bgcolor'])) ? $data['bgcolor'] : '#FFFFFF', '#title' => t('Background color'), '#description' => t('The background color to use for exposed areas of the image. Use web-style hex colors (#FFFFFF for white, #000000 for black).'), ); return $form; }
function theme_imagecache_rotate($element) { $output = t('degrees: ') . $element['#value']['degrees'] .', '; $output .= t('randomize: ') . (($element['#value']['random']) ? t('Yes') : t('No')) .', '; $output .= t('background: ') . $element['#value']['bgcolor']; return $output; }
function imagecache_rotate_image(&$image, $data) { // Set sane default values. $data['degrees'] = $data['degrees'] ? $data['degrees'] : 0; $data['random'] = $data['random'] ? $data['random'] : false; $data['bgcolor'] = $data['bgcolor'] ? $data['bgcolor'] : '#FFFFFF';
// Manipulate the if we need to randomize, and convert to proper colors. $data['bgcolor'] = '0x'. str_replace('#', '', $data['bgcolor']);
if (!empty($data['random'])) { $degrees = abs((float)$data['degrees']); $data['degrees'] = rand(-1 * $degrees, $degrees); }
if (!imageapi_image_rotate($image, $data['degrees'], $data['bgcolor'])) { watchdog('imagecache', t('imagecache_rotate_image failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, true))), WATCHDOG_ERROR); return false; } return true; }
|