Changeset 1502

Show
Ignore:
Timestamp:
05/31/10 15:37:28 (4 years ago)
Author:
tboutell
Message:

1. The media repository backend now supports cropping parameters in image URLs. That is, you can request:

/uploads/media_items/myslug.width.height.cropleft.cropTop.cropWidth.cropHeight.c.jpg

And the specified cropping rectangle will be applied to the image before scaling to width/height.

2. gd now shrinks one axis rather than expanding one axis when asked to crop-and-scale to a different aspect ratio. Fixes #410

Location:
plugins/apostrophePlugin/branches/features/cropping/lib
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • plugins/apostrophePlugin/branches/features/cropping/lib/action/BaseaMediaBackendActions.class.php

    r1255 r1502  
    3939      array_keys(aMediaItemTable::$mimeTypes))); 
    4040    $this->forward404Unless(($resizeType !== 'c') || ($resizeType !== 's')); 
    41     $output = $this->getDirectory() .  
    42       DIRECTORY_SEPARATOR . "$slug.$width.$height.$resizeType.$format"; 
     41    // EDITED FOR ARBITRARY CROPPING 
     42    $cropLeft = $request->getParameter('cropLeft'); 
     43    $cropTop = $request->getParameter('cropTop'); 
     44    $cropWidth = $request->getParameter('cropWidth'); 
     45    $cropHeight = $request->getParameter('cropHeight'); 
     46     
     47    if (!is_null($cropWidth) && !is_null($cropHeight) && !is_null($cropLeft) && !is_null($cropTop)) 
     48    { 
     49      $cropLeft = ceil($cropLeft + 0); 
     50      $cropTop = ceil($cropTop + 0); 
     51      $cropWidth = ceil($cropWidth + 0); 
     52      $cropHeight = ceil($cropHeight + 0); 
     53      $resizeType = 'c'; 
     54       
     55      $output = $this->getDirectory() .  
     56        DIRECTORY_SEPARATOR . "$slug.$width.$height.$cropLeft.$cropTop.$cropWidth.$cropHeight.$resizeType.$format";       
     57    } 
     58    else 
     59    { 
     60      $cropLeft = null; 
     61      $cropTop = null; 
     62      $cropWidth = null; 
     63      $cropHeight = null; 
     64      $output = $this->getDirectory() .  
     65        DIRECTORY_SEPARATOR . "$slug.$width.$height.$resizeType.$format"; 
     66    } 
     67 
    4368    // If .htaccess has not been set up, or we are not running 
    4469    // from the default front controller, then we may get here 
     
    5782        $method = 'scaleToFit'; 
    5883      } 
    59       $quality = sfConfig::get('app_aMedia_jpeg_quality', 75); 
    6084      aImageConverter::$method( 
    6185        aMediaItemTable::getDirectory() . 
     
    6589        $width, 
    6690        $height, 
    67         sfConfig::get('app_aMedia_jpeg_quality', 75)); 
     91        sfConfig::get('app_aMedia_jpeg_quality', 75), 
     92        $cropLeft, 
     93        $cropTop, 
     94        $cropWidth, 
     95        $cropHeight); 
    6896    } 
    6997    // The FIRST time, we output this here. Later it 
  • plugins/apostrophePlugin/branches/features/cropping/lib/toolkit/aImageConverter.class.php

    r1499 r1502  
    347347        $width = $scaleParameters['xysize'][0]; 
    348348        $height = $scaleParameters['xysize'][1]; 
     349        // This was backwards until 05/31/2010, making things bigger rather than smaller if their 
     350        // aspect ratios differed from the original. Be consistent with netpbm which makes things 
     351        // smaller not bigger 
    349352        if (($width / $height) > ($swidth / $sheight)) 
    350353        { 
    351           // Wider than the original. So it will be shorter than requested 
    352           $height = ceil($width * ($sheight / $swidth)); 
     354          // Wider than the original. So it will be narrower than requested 
     355          $width = ceil($height * ($swidth / $sheight)); 
    353356        } 
    354357        else 
    355358        { 
    356           // Taller than the original. So it will be narrower than requested 
    357           $width = ceil($height * ($swidth / $sheight)); 
     359          // Taller than the original. So it will be shorter than requested 
     360          $height = ceil($width * ($sheight / $swidth)); 
    358361        } 
    359362        $out = self::createTrueColorAlpha($width, $height); 
  • plugins/apostrophePlugin/branches/features/cropping/lib/toolkit/aMediaRouting.php

    r883 r1502  
    2626        'action' => 'original' 
    2727      ), array('slug' => '^' . aTools::getSlugRegexpFragment() . '$', 'format' => '^(jpg|png|gif|pdf)$'))); 
     28 
     29      $route = new sfRoute('/uploads/media_items/:slug.:width.:height.:cropLeft.:cropTop.:cropWidth.:cropHeight.:resizeType.:format', array( 
     30        'module' => 'aMediaBackend', 
     31        'action' => 'image' 
     32      ), array( 
     33        'slug' => '^' . aTools::getSlugRegexpFragment() . '$', 
     34        'width' => '^\d+$', 
     35        'height' => '^\d+$', 
     36        'cropLeft' => '^\d+$', 
     37        'cropTop' => '^\d+$', 
     38        'cropWidth' => '^\d+$', 
     39        'cropHeight' => '^\d+$', 
     40        'resizeType' => '^\w$', 
     41        'format' => '^(jpg|png|gif)$' 
     42      )); 
     43      $r->prependRoute('a_media_image_cropped', $route); 
    2844       
    2945      $route = new sfRoute('/uploads/media_items/:slug.:width.:height.:resizeType.:format', array(