/[drupal]/contributions/modules/img_assist/img_assist.module
ViewVC logotype

Diff of /contributions/modules/img_assist/img_assist.module

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

revision 1.68.2.50.2.17.2.6, Wed Jul 15 22:58:17 2009 UTC revision 1.68.2.50.2.17.2.7, Thu Jul 23 10:06:14 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: img_assist.module,v 1.68.2.50.2.17.2.5 2009/06/09 00:55:10 sun Exp $  // $Id: img_assist.module,v 1.68.2.50.2.17.2.6 2009/07/15 22:58:17 sun Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 465  function img_assist_filter($op, $delta = Line 465  function img_assist_filter($op, $delta =
465    
466      case 'description':      case 'description':
467        return t('Add images to your posts with Image assist.');        return t('Add images to your posts with Image assist.');
468    
469    //    case 'no cache':
470    //      return TRUE;
471    
472      case 'process':      case 'process':
473        $processed = FALSE;        $processed = FALSE;
474        foreach (img_assist_get_macros($text) as $unexpanded_macro => $macro) {        foreach (img_assist_get_macros($text) as $unexpanded_macro => $macro) {
# Line 1353  function img_assist_render_image($attrib Line 1356  function img_assist_render_image($attrib
1356    
1357    if ($attributes['nid']) {    if ($attributes['nid']) {
1358      $node = node_load($attributes['nid']);      $node = node_load($attributes['nid']);
1359    
1360      // Get size.      // Get image size.
1361      $width  = $attributes['width'];      $width  = (int) $attributes['width'];
1362      $height = $attributes['height'];      $height = (int) $attributes['height'];
1363        $default_sizes = image_get_sizes();
1364      if ($width || $height) {      if ($width || $height) {
1365        // Check to ensure that the dimensions don't exceed the max set in the        // Check to ensure that the dimensions don't exceed the max set in the
1366        // img_assist settings.        // img_assist settings.
# Line 1383  function img_assist_render_image($attrib Line 1387  function img_assist_render_image($attrib
1387    
1388            // Get new width and height for this inline image.            // Get new width and height for this inline image.
1389            // If height is either left out or larger than width then            // If height is either left out or larger than width then
1390            // width is the controlling factor.            // Width is controlling factor.
1391            if (!$height || round($width / $aspect_ratio) <= $height) {            if (!$height || ($width && round($width / $aspect_ratio) <= $height)) {
1392              $height = round($width / $aspect_ratio);              $height = round($width / $aspect_ratio);
1393            }            }
1394            // Else, width is either left out or larger than height so            // Else, width is either left out or larger than height so
1395            // height is controlling factor.            // Height is controlling factor.
1396            else {            else {
1397              $width = round($height * $aspect_ratio);              $width = round($height * $aspect_ratio);
1398            }            }
1399    
1400            // Compare new width and height to existing image derivative sizes.            // Find out whether the given width/height is the same as (or extremely
1401              // close to) a default image derivative size; if so, we will use the
1402              // default size instead of generating a custom image.
1403            $diag_size_new = sqrt(pow($width, 2) + pow($height, 2));            $diag_size_new = sqrt(pow($width, 2) + pow($height, 2));
1404            $closest_difference = 9999;            $closest_difference = 9999;
1405    
1406            foreach (image_get_sizes() as $key => $stdsize) {            foreach ($default_sizes as $key => $stdsize) {
1407              $width_std = $stdsize['width'];              $width_std = $stdsize['width'];
1408              $height_std = $stdsize['height'];              $height_std = $stdsize['height'];
1409              // Get default width and height, taking the aspect ratio into account.              // Diagonal size calculations require a width or height.
1410              if (round($width_std / $aspect_ratio) <= $height_std) {              if (!$height_std && !$width_std) {
1411                // Width is controlling factor.                // For the original image, we can fall back to actual dimensions
1412                  // though. In fact, IMAGE_ORIGINAL can either have maximum
1413                  // dimensions (so aspect ratio based calculations below will apply)
1414                  // or the real dimensions (which must be considered as valid
1415                  // "derivative size").
1416                  // Note that this annuls the 'use original size' user permission.
1417                  if ($key !== IMAGE_ORIGINAL) {
1418                    continue;
1419                  }
1420                  else {
1421                    $width_std = $original_size['width'];
1422                    $height_std = $original_size['height'];
1423                  }
1424                }
1425                // Calculate default width and height based on aspect ratio.
1426                // Width is controlling factor.
1427                if (!$height_std && ($width_std && round($width_std / $aspect_ratio) <= $height_std)) {
1428                $height_std = round($width_std / $aspect_ratio);                $height_std = round($width_std / $aspect_ratio);
1429              }              }
1430                // Height is controlling factor.
1431              else {              else {
               // Height is controlling factor.  
1432                $width_std = round($height_std * $aspect_ratio);                $width_std = round($height_std * $aspect_ratio);
1433              }              }
1434              // Get the diagonal size of this standard image.              // Calculate diagonal size of this default size.
1435              $diag_size_std = sqrt(pow($width_std, 2) + pow($height_std, 2));              $diag_size_std = sqrt(pow($width_std, 2) + pow($height_std, 2));
1436              $difference = abs($diag_size_new - $diag_size_std);              $difference = abs($diag_size_new - $diag_size_std);
1437              if ($difference < $closest_difference) {              if ($difference < $closest_difference) {
# Line 1417  function img_assist_render_image($attrib Line 1439  function img_assist_render_image($attrib
1439                $closest_difference = $difference;                $closest_difference = $difference;
1440              }              }
1441            }            }
1442              // If, for any reason, no default image derivative size has a width or
1443            // Find out if desired width/height is the same (or extremely close)            // height, fall back to IMAGE_THUMBNAIL.
1444            // to the size of a default image derivative; if so, we will use the            if (!isset($closest_std_size)) {
1445            // default size image instead of generating our own image.              $closest_std_size = IMAGE_THUMBNAIL;
1446              }
1447    
1448            if ($closest_difference < 3) {            if ($closest_difference < 3) {
1449              $create_custom = FALSE;              $create_custom = FALSE;
1450            }            }
# Line 1466  function img_assist_render_image($attrib Line 1490  function img_assist_render_image($attrib
1490          $size['key'] = $closest_std_size;          $size['key'] = $closest_std_size;
1491        }        }
1492      }      }
1493      // Default to thumbnail if width and/or height is missing.      // Default to thumbnail if width and height is missing.
1494      else {      else {
1495        $size        = image_get_sizes();        $size = $default_sizes[IMAGE_THUMBNAIL];
       $size        = $size[IMAGE_THUMBNAIL];  
1496        $size['key'] = IMAGE_THUMBNAIL;        $size['key'] = IMAGE_THUMBNAIL;
1497      }      }
1498      return theme('img_assist_inline', $node, $size, $attributes);      return theme('img_assist_inline', $node, $size, $attributes);

Legend:
Removed from v.1.68.2.50.2.17.2.6  
changed lines
  Added in v.1.68.2.50.2.17.2.7

  ViewVC Help
Powered by ViewVC 1.1.2