To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

Show
Ignore:
Timestamp:
08/08/10 12:18:34 (22 months ago)
Author:
tboutell
Message:

Merged the cropping branch back to trunk:

Cropping is now available in the media repository. Every time you select an image for use on the site you have the opportunity to crop it. The image size constraints of the slot are taken into account. This means that you can satisfy a given set of constraints by cropping a wide variety of images that would not have been eligible for selection before.

Crops of existing images appear in the database as separate aMediaItem objects but do not duplicate the original image file. This means that many crops of a single source image can exist without significant overhead.

The slug field of a cropped version of an image contains cropping parameters. When rendering the image, Symfony routes spot these and crop the original file as needed.

By approaching the problem this way we have avoided the need for code that takes advantage of the media repository's image selection capabilities to change in any way in order to take advantage of cropping.

The single-image-select behavior of Apostrophe has changed to accommodate the extra cropping step. Single select for PDFs and videos still uses the selectSingle partial because they cannot be cropped.

Thanks to Spike Broehm for his contributions to the cropping project.

Fixes #227

Location:
plugins/apostrophePlugin/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • plugins/apostrophePlugin/trunk

  • plugins/apostrophePlugin/trunk/lib/action/BaseaMediaBackendActions.class.php

    r1255 r1917  
    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      // Explicit cropping always preempts any automatic cropping, so there's no difference between c and s, 
     54      // and only the cropOriginal method actually supports cropping parameters, so 
     55      $resizeType = 'c'; 
     56       
     57      $output = $this->getDirectory() .  
     58        DIRECTORY_SEPARATOR . "$slug.$cropLeft.$cropTop.$cropWidth.$cropHeight.$width.$height.$resizeType.$format";       
     59    } 
     60    else 
     61    { 
     62      $cropLeft = null; 
     63      $cropTop = null; 
     64      $cropWidth = null; 
     65      $cropHeight = null; 
     66      $output = $this->getDirectory() .  
     67        DIRECTORY_SEPARATOR . "$slug.$width.$height.$resizeType.$format"; 
     68    } 
     69 
    4370    // If .htaccess has not been set up, or we are not running 
    4471    // from the default front controller, then we may get here 
     
    5784        $method = 'scaleToFit'; 
    5885      } 
    59       $quality = sfConfig::get('app_aMedia_jpeg_quality', 75); 
    6086      aImageConverter::$method( 
    6187        aMediaItemTable::getDirectory() . 
     
    6591        $width, 
    6692        $height, 
    67         sfConfig::get('app_aMedia_jpeg_quality', 75)); 
     93        sfConfig::get('app_aMedia_jpeg_quality', 75), 
     94        $cropLeft, 
     95        $cropTop, 
     96        $cropWidth, 
     97        $cropHeight); 
    6898    } 
    6999    // The FIRST time, we output this here. Later it