/[drupal]/contributions/modules/imagecache_actions/canvasactions.inc
ViewVC logotype

Diff of /contributions/modules/imagecache_actions/canvasactions.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.4.19, Fri Oct 30 14:03:54 2009 UTC revision 1.1.4.20, Fri Oct 30 16:22:23 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: canvasactions.inc,v 1.1.4.18 2009/09/05 02:11:58 dman Exp $  // $Id: canvasactions.inc,v 1.1.4.19 2009/10/30 14:03:54 dman Exp $
3  /**  /**
4   * @file Helper functions for the text2canvas action for imagecache   * @file Helper functions for the text2canvas action for imagecache
5   *   *
# Line 909  function theme_canvasactions_roundedcorn Line 909  function theme_canvasactions_roundedcorn
909   * @return a form definition   * @return a form definition
910   */   */
911  function canvasactions_aspect_form($action) {  function canvasactions_aspect_form($action) {
912    $defaults = array(  );    $defaults = array( 'ratio_adjustment' => 1 );
913    $action = array_merge($defaults, (array)$action);    $action = array_merge($defaults, (array)$action);
914    
915    $form = array(    $form = array(
# Line 936  function canvasactions_aspect_form($acti Line 936  function canvasactions_aspect_form($acti
936      '#default_value' => $action['landscape'],      '#default_value' => $action['landscape'],
937      '#options' => $presets,      '#options' => $presets,
938    );    );
939    
940      $form['ratio_adjustment'] = array(
941        '#type' => 'textfield',
942        '#title' => t('Ratio Adjustment (advanced)'),
943        '#size' => 3,
944        '#default_value' => $action['ratio_adjustment'],
945        '#description' => t("
946    This allows you to bend the rules for how different the proportions need to be to trigger the switch.
947    <br/>If the (width/height)*n is greater than 1, use 'landscape', otherwise use 'portrait'.
948    <br/>When n = 1 (the default) it will switch between portrait and landscape modes.
949    <br/>If n > 1, images that are slightly wide will still be treated as portraits.
950    If n < 1 then blunt portraits will be treated as landscape.
951        "),
952      );
953    
954    
955    return $form;    return $form;
956  }  }
957    
# Line 946  function canvasactions_aspect_form($acti Line 962  function canvasactions_aspect_form($acti
962  function theme_canvasactions_aspect($element) {  function theme_canvasactions_aspect($element) {
963    $action = $element['#value'];    $action = $element['#value'];
964    $presets = imagecache_presets(TRUE);    $presets = imagecache_presets(TRUE);
965    return 'Portrait size: <strong>'. $presets[$action['portrait']]['presetname'] . '</strong>. Landscape size: <strong>'. $presets[$action['landscape']]['presetname'] .'</strong>' ;    $ratio_adjustment = '';
966      if ($action['ratio_adjustment'] != 1) {
967        $ratio_adjustment = " (switch at 1:{$action['ratio_adjustment']})";
968      }
969      return 'Portrait size: <strong>'. $presets[$action['portrait']]['presetname'] . '</strong>. Landscape size: <strong>'. $presets[$action['landscape']]['presetname'] .'</strong>'. $ratio_adjustment ;
970  }  }
971    
972  /**  /**
# Line 959  function theme_canvasactions_aspect($ele Line 979  function theme_canvasactions_aspect($ele
979   * @param $action   * @param $action
980   */   */
981  function canvasactions_aspect_image(&$image, $action = array()) {  function canvasactions_aspect_image(&$image, $action = array()) {
982    $preset_id = ($image->info['width'] > $image->info['height'] ) ? $action['landscape'] : $action['portrait'];    $ratio_adjustment = 0 + $action['ratio_adjustment'];
983      if (!$ratio_adjustment) {
984        $ratio_adjustment = 1;
985      }
986      $aspect = $image->info['width'] / $image->info['height'];
987      // width / height * adjustment. If > 1, it's wide.
988      $preset_id = (($aspect * $ratio_adjustment) > 1) ? $action['landscape'] : $action['portrait'];
989    $preset = imagecache_preset($preset_id);    $preset = imagecache_preset($preset_id);
990    
991    // Run the preset actions ourself. Cannot invoke a preset from the top as it handles filenames, not image objects.    // Run the preset actions ourself. Cannot invoke a preset from the top as it handles filenames, not image objects.

Legend:
Removed from v.1.1.4.19  
changed lines
  Added in v.1.1.4.20

  ViewVC Help
Powered by ViewVC 1.1.2