<?php
/**
 * @file
 * This module provides an image effect to alter the height and width
 * attributes of the final image.
 */

/**
 * Implements hook_image_effect_info().
 *
 * Return the descriptions for the supported actions.
 */
function image_dimensions_image_effect_info() {
  $effects = array();

  $effects['image_dimensions'] = array(
    'label' => t('Output at 100% width'),
    'effect callback' => 'image_dimensions_set_width_effect',
    'dimensions callback' => 'image_dimensions_dimensions',
  );

  return $effects;
}


/**
 * Image effect callback;
 *
 * @param $image
 *   An image object returned by image_load().
 * @param $data
 *   An array of attributes to use when performing the image effect
 *   with the following items:
 *   - "width": An integer representing the desired width in pixels.
 *   - "height": An integer representing the desired height in pixels.
 * @return
 *   TRUE on success.
 */
function image_dimensions_set_width_effect(&$image, $data) {
  return TRUE;
}


/**
 * Image dimensions callback.
 *
 * @param $dimensions
 *   Dimensions to be modified - an array with components width and height, in
 *   pixels.
 * @param $data
 *   An array of attributes to use when performing the image effect with the
 *   following items:
 *   - "width": An integer representing the desired width in pixels.
 *   - "height": An integer representing the desired height in pixels.
 */
function image_dimensions_dimensions(&$dimensions) {
  $dimensions['width'] = '100%';
  $dimensions['height'] = '';
}
