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/modules/aMedia/templates/_multipleList.php

    r1914 r1917  
    55<?php use_helper('I18N', 'jQuery') ?> 
    66 
    7 <?php $ids = array() ?> 
    8  
    97<?php foreach ($items as $item): ?> 
    108<li id="a-media-selection-list-item-<?php echo $item->getId() ?>" class="a-media-selection-list-item"> 
    119        <?php $id = $item->getId() ?> 
    1210  <ul class="a-controls a-media-multiple-list-controls">         
     11                <li> 
     12                        <a href="#crop" onclick="return false;" class="a-btn icon a-crop no-label" title="<?php echo __('Crop', null, 'apostrophe') ?>"><?php echo __('Crop', null, 'apostrophe') ?></a> 
     13                </li> 
    1314          <li><?php echo jq_link_to_remote(__("remove this item", null, 'apostrophe'), 
    1415    array( 
    1516      'url' => 'aMedia/multipleRemove?id='.$id, 
    1617      'update' => 'a-media-selection-list', 
    17                         'complete' => 'aUI("a-media-selection-list"); aMediaDeselectItem('.$id.')',  
     18                        'complete' => 'aUI("a-media-selection-list"); aMediaDeselectItem('.$id.'); aMediaUpdatePreview()',  
    1819    ), array( 
    1920                        'class'=> 'a-btn icon a-delete no-label', 
     
    2223        </ul>    
    2324 
    24         <div class="a-media-selected-item-drag-overlay" title="<?php echo __('Drag &amp; Drop to Order', null, 'apostrophe') ?>"></div> 
     25  <?php if (aMediaTools::isMultiple()): ?> 
     26        <div class="a-media-selected-item-drag-overlay" title="<?php echo __('Drag &amp; Drop to Order', null, 'apostrophe') ?>"></div> 
     27  <?php endif ?> 
    2528        <div class="a-media-selected-item-overlay"></div> 
    26   <img src="<?php echo url_for($item->getScaledUrl(aMediaTools::getOption('selected_constraints'))) ?>" /> 
    27  
    28           <?php $ids[] = $item->getId() ?> 
    29  
     29  <img src="<?php echo url_for($item->getCropThumbnailUrl()) ?>" class="a-thumbnail" /> 
    3030</li> 
    3131<?php endforeach ?> 
     
    3333<script type="text/javascript" charset="utf-8"> 
    3434 
    35         function aMediaItemsIndicateSelected(ids) 
     35        function aMediaItemsIndicateSelected(cropOptions) 
    3636        { 
    37                 $('.a-media-selected-overlay').remove(); 
     37          var ids = cropOptions.ids; 
     38          aCrop.init(cropOptions); 
     39                $('.a-media-selected-overlay').remove();                 
     40                $('.a-media-selected').removeClass('a-media-selected'); 
    3841                 
    3942          var i; 
     
    4750                        } 
    4851                } 
    49          
     52                         
    5053                $('.a-media-item.a-media-selected').each(function(){ 
    5154                        $(this).children('.a-media-item-thumbnail').prepend('<div class="a-media-selected-overlay"></div>'); 
    5255                }); 
     56                 
     57                $('#a-media-selection-list-caption').hide(); 
     58                if (!ids.length) { 
     59      $('#a-media-selection-list-caption').show(); 
     60                } 
    5361 
    5462                $('.a-media-selected-overlay').fadeTo(0, 0.66); 
     63        } 
     64         
     65        function aMediaUpdatePreview() 
     66        { 
     67          $('#a-media-selection-preview').load('<?php echo url_for('aMedia/updateMultiplePreview') ?>', function(){ 
     68          // the preview images are by default set to display:none 
     69            $('#a-media-selection-preview li:first').addClass('current'); 
     70            // set up cropping again; do hard reset to reinstantiate Jcrop 
     71            aCrop.resetCrop(true); 
     72          }); 
    5573        } 
    5674 
     
    6684 
    6785        $(document).ready(function() { // On page ready indicate selected items 
    68                 aMediaItemsIndicateSelected(<?php echo json_encode($ids) ?>)  
     86          var cropOptions = { 
     87      ids: <?php echo json_encode(aMediaTools::getSelection()) ?>, 
     88      aspectRatio: <?php echo aMediaTools::getAspectRatio() ?>, 
     89      minimumSize: [<?php echo aMediaTools::getAttribute('minimum-width') ?>, <?php echo aMediaTools::getAttribute('minimum-height') ?>], 
     90      maximumSize: [<?php echo aMediaTools::getAttribute('maximum-width') ?>, <?php echo aMediaTools::getAttribute('maximum-height') ?>], 
     91      <?php // width height cropLeft cropTop cropWidth cropHeight hashed by image id ?> 
     92      imageInfo: <?php echo json_encode(aMediaTools::getAttribute('imageInfo')) ?> 
     93    }; 
     94           
     95                aMediaItemsIndicateSelected(cropOptions); 
     96                 
    6997                $('.a-media-selected-item-overlay').fadeTo(0,.35); //cross-browser opacity for overlay 
    7098                $('.a-media-selection-list-item').hover(function(){