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/_describeConstraints.php

    r1655 r1917  
    11<?php // Yes, this is template code, but we use regular PHP syntax because we are building a sentence and the introduction of ?> 
    2 <?php // newlines wrecks the punctuation. ?> 
    3 <?php  
    4 use_helper('I18N'); 
    5 $clauses = array(); 
    6 if (aMediaTools::getAttribute('aspect-width') && aMediaTools::getAttribute('aspect-height')) 
    7 { 
    8   $clauses[] = __('A %w%x%h% aspect ratio', array('%w%' => aMediaTools::getAttribute('aspect-width'), '%h%' => aMediaTools::getAttribute('aspect-height')), 'apostrophe'); 
    9 } 
    10 if (aMediaTools::getAttribute('minimum-width')) 
    11 { 
    12   $clauses[] = __('A minimum width of %mw% pixels', array('%mw%' => aMediaTools::getAttribute('minimum-width')), 'apostrophe'); 
    13 } 
    14 if (aMediaTools::getAttribute('minimum-height')) 
    15 { 
    16   $clauses[] = __('A minimum height of %mh% pixels', array('%mh%' => aMediaTools::getAttribute('minimum-height')), 'apostrophe'); 
    17 } 
    18 if (aMediaTools::getAttribute('width')) 
    19 { 
    20   $clauses[] = __('A width of exactly %w% pixels', array('%w%' => aMediaTools::getAttribute('width')), 'apostrophe'); 
    21 } 
    22 if (aMediaTools::getAttribute('height')) 
    23 { 
    24   $clauses[] = __('A height of exactly %h% pixels', array('%h%' => aMediaTools::getAttribute('height')), 'apostrophe'); 
    25 } 
    26 if (aMediaTools::getAttribute('type')) 
    27 { 
    28   // Internationalize the plural so that can be correct too 
    29   $type = __(aMediaTools::getAttribute('type') . "s", null, 'apostrophe'); 
    30 }  
    31 else 
    32 { 
    33   $type = __("items", null, 'apostrophe'); 
    34 } 
    35 if (count($clauses)) 
    36 { 
    37   // Markup change: for I18N it's better to use a list here rather than 
    38   // trying to create a sentence with commas and 'and' 
    39   echo('<h3 class="a-constraints-description">' . __("Displaying only %t% with:", array('%t%' => $type), 'apostrophe') . '</h3>'); 
    40   echo('<ul class="a-constraints">'); 
    41   foreach ($clauses as $clause) 
     2<?php // newlines wrecks the punctuation. (OK, we're building a ul list now...) ?> 
     3<?php use_helper('I18N') ?> 
     4<?php // Images support cropping, which makes some of the constraints unnecessary to display ?> 
     5<?php // With other media types we must find an item that satisfies all of them. ?> 
     6<?php if (aMediaTools::getAttribute('type') === 'image'): ?> 
     7  <?php // We went with something simpler when cropping is present ?> 
     8        <?php if ($limitSizes): ?> 
     9        <h4 class="a-help"><?php echo __('Some images in your media library may not be large enough to be selected. Only images that can be used are displayed below.', null, 'apostrophe') ?></h4> 
     10        <?php endif ?> 
     11<?php else: ?> 
     12  <?php // No cropping, their only hope is to get proper details from us on what is allowed ?> 
     13  <?php 
     14  $clauses = array(); 
     15  if (aMediaTools::getAttribute('aspect-width') && aMediaTools::getAttribute('aspect-height')) 
    4216  { 
    43     echo('<li>' . $clause . '</li>'); 
     17    $clauses[] = __('A %w%x%h% aspect ratio', array('%w%' => aMediaTools::getAttribute('aspect-width'), '%h%' => aMediaTools::getAttribute('aspect-height')), 'apostrophe'); 
    4418  } 
    45   echo('</ul>'); 
    46 } 
     19  if (aMediaTools::getAttribute('minimum-width')) 
     20  { 
     21    $clauses[] = __('A minimum width of %mw% pixels', array('%mw%' => aMediaTools::getAttribute('minimum-width')), 'apostrophe'); 
     22  } 
     23  if (aMediaTools::getAttribute('minimum-height')) 
     24  { 
     25    $clauses[] = __('A minimum height of %mh% pixels', array('%mh%' => aMediaTools::getAttribute('minimum-height')), 'apostrophe'); 
     26  } 
     27  if (aMediaTools::getAttribute('width')) 
     28  { 
     29    $clauses[] = __('A width of exactly %w% pixels', array('%w%' => aMediaTools::getAttribute('width')), 'apostrophe'); 
     30  } 
     31  if (aMediaTools::getAttribute('height')) 
     32  { 
     33    $clauses[] = __('A height of exactly %h% pixels', array('%h%' => aMediaTools::getAttribute('height')), 'apostrophe'); 
     34  } 
     35  if (aMediaTools::getAttribute('type')) 
     36  { 
     37    // Internationalize the plural so that can be correct too 
     38    $type = __(aMediaTools::getAttribute('type') . "s", null, 'apostrophe'); 
     39  }  
     40  else 
     41  { 
     42    $type = __("items", null, 'apostrophe'); 
     43  } 
     44  if (count($clauses)) 
     45  { 
     46    // Markup change: for I18N it's better to use a list here rather than 
     47    // trying to create a sentence with commas and 'and' 
     48    echo('<h4 class="a-constraints-description">' . __("Displaying only %t% with:", array('%t%' => $type), 'apostrophe') . '</h4>'); 
     49    echo('<ul class="a-constraints">'); 
     50    foreach ($clauses as $clause) 
     51    { 
     52      echo('<li>' . $clause . '</li>'); 
     53    } 
     54    echo('</ul>'); 
     55  } 
     56  ?> 
     57<?php endif ?>