Changeset 10552
- Timestamp:
- Apr 21, 2011, 11:55:20 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions_upload.inc.php
r10383 r10552 26 26 // add default event handler for image and thumbnail resize 27 27 add_event_handler('upload_image_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 7); 28 add_event_handler('upload_thumbnail_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 7);28 add_event_handler('upload_thumbnail_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 9); 29 29 30 30 function get_upload_form_config() … … 89 89 'can_be_null' => false, 90 90 'error_message' => l10n('The thumbnail image quality must be a number between %d and %d'), 91 ), 92 93 'thumb_crop' => array( 94 'default' => false, 95 'can_be_null' => false, 96 ), 97 98 'thumb_follow_orientation' => array( 99 'default' => true, 100 'can_be_null' => false, 91 101 ), 92 102 … … 327 337 $conf['upload_form_thumb_maxheight'], 328 338 $conf['upload_form_thumb_quality'], 329 true 339 true, 340 $conf['upload_form_thumb_crop'], 341 $conf['upload_form_thumb_follow_orientation'] 330 342 ); 331 343 … … 518 530 } 519 531 520 function pwg_image_resize($result, $source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false )532 function pwg_image_resize($result, $source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false, $crop=false, $follow_orientation=true) 521 533 { 522 534 if ($result !== false) … … 530 542 if (is_imagick() and $extension != 'gif') 531 543 { 532 return pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata );544 return pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata, $crop, $follow_orientation); 533 545 } 534 546 else 535 547 { 536 return pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality );537 } 538 } 539 540 function pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality )548 return pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $crop, $follow_orientation); 549 } 550 } 551 552 function pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $crop=false, $follow_orientation=true) 541 553 { 542 554 if (!function_exists('gd_info')) … … 577 589 $source_width = imagesx($source_image); 578 590 $source_height = imagesy($source_image); 579 591 592 // Crop 593 if ($crop) 594 { 595 $coord = get_crop_coord($source_width, $source_height, $max_width, $max_height, $follow_orientation); 596 } 597 580 598 $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation); 581 599 … … 596 614 0, 597 615 0, 598 0,599 0,616 $crop ? $coord['x'] : 0, 617 $crop ? $coord['y'] : 0, 600 618 $resize_dimensions['width'], 601 619 $resize_dimensions['height'], … … 631 649 } 632 650 633 function pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false )651 function pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false, $crop=false, $follow_orientation=true) 634 652 { 635 653 // extension of the picture filename … … 647 665 $source_width = $image->getImageWidth(); 648 666 $source_height = $image->getImageHeight(); 667 668 // Crop 669 if ($crop) 670 { 671 $coord = get_crop_coord($source_width, $source_height, $max_width, $max_height, $follow_orientation); 672 $image->cropImage($source_width, $source_height, $coord['x'], $coord['y']); 673 } 649 674 650 675 $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation); … … 726 751 727 752 return $rotation; 753 } 754 755 function get_crop_coord(&$source_width, &$source_height, &$max_width, &$max_height, $follow_orientation) 756 { 757 $x = 0; 758 $y = 0; 759 760 if ($source_width < $source_height and $follow_orientation) 761 { 762 list($width, $height) = array($max_height, $max_width); 763 $max_width = $width; 764 $max_height = $height; 765 } 766 767 $img_ratio = $source_width / $source_height; 768 $dest_ratio = $max_width / $max_height; 769 770 if($dest_ratio > $img_ratio) 771 { 772 $destHeight = round($source_width * $max_height / $max_width); 773 $y = round(($source_height - $destHeight) / 2 ); 774 $source_height = $destHeight; 775 } 776 elseif ($dest_ratio < $img_ratio) 777 { 778 $destWidth = round($source_height * $max_width / $max_height); 779 $x = round(($source_width - $destWidth) / 2 ); 780 $source_width = $destWidth; 781 } 782 783 return array('x' => $x, 'y' => $y); 728 784 } 729 785 -
trunk/admin/photos_add_settings.php
r8728 r10552 76 76 $fields[] = 'thumb_maxheight'; 77 77 $fields[] = 'thumb_quality'; 78 78 $fields[] = 'thumb_crop'; 79 $fields[] = 'thumb_follow_orientation'; 80 79 81 foreach ($fields as $field) 80 82 { -
trunk/admin/themes/default/template/photos_add_settings.tpl
r9586 r10552 1 {footer_script}{literal} 1 {footer_script} 2 var width = '{'Width'|@translate}'; 3 var height = '{'Height'|@translate}'; 4 var max_width = '{'Maximum Width'|@translate}'; 5 var max_height = '{'Maximum Height'|@translate}'; 6 7 {literal} 2 8 jQuery(document).ready(function(){ 3 9 function toggleResizeFields(prefix) { 4 10 var checkbox = jQuery("#"+prefix+"_resize"); 5 11 var needToggle = jQuery("input[name^="+prefix+"_]").not(checkbox).not(jQuery("#hd_keep")).parents('tr'); 6 7 12 8 13 if (jQuery(checkbox).is(':checked')) { … … 22 27 } 23 28 29 function toggleCropFields(prefix) { 30 if (jQuery("#"+prefix+"_crop").is(':checked')) { 31 jQuery("#"+prefix+"_width_th").text(width); 32 jQuery("#"+prefix+"_height_th").text(height); 33 jQuery("#"+prefix+"_follow_orientation_tr").show(); 34 } 35 else { 36 jQuery("#"+prefix+"_width_th").text(max_width); 37 jQuery("#"+prefix+"_height_th").text(max_height); 38 jQuery("#"+prefix+"_follow_orientation_tr").hide(); 39 } 40 41 } 42 24 43 toggleResizeFields("websize"); 25 44 jQuery("#websize_resize").click(function () {toggleResizeFields("websize")}); … … 27 46 toggleResizeFields("hd"); 28 47 jQuery("#hd_resize").click(function () {toggleResizeFields("hd")}); 48 49 toggleCropFields("thumb"); 50 jQuery("#thumb_crop").click(function () {toggleCropFields("thumb")}); 29 51 30 52 function toggleHdFields() { … … 82 104 <table> 83 105 <tr> 84 <th>{'Maximum Width'|@translate}</th> 106 <th><label for="thumb_crop">{'Crop'|@translate}</label></th> 107 <td><input type="checkbox" name="thumb_crop" id="thumb_crop" {$values.thumb_crop}></td> 108 </tr> 109 <tr id="thumb_follow_orientation_tr"> 110 <th><label for="thumb_follow_orientation">{'Follow Orientation'|@translate}</label></th> 111 <td><input type="checkbox" name="thumb_follow_orientation" id="thumb_follow_orientation" {$values.thumb_follow_orientation}></td> 112 </tr> 113 <tr> 114 <th id="thumb_width_th">{'Maximum Width'|@translate}</th> 85 115 <td><input type="text" name="thumb_maxwidth" value="{$values.thumb_maxwidth}" size="4" maxlength="4"> {'pixels'|@translate}</td> 86 116 </tr> 87 117 <tr> 88 <th >{'Maximum Height'|@translate}</th>118 <th id="thumb_height_th">{'Maximum Height'|@translate}</th> 89 119 <td><input type="text" name="thumb_maxheight" value="{$values.thumb_maxheight}" size="4" maxlength="4"> {'pixels'|@translate}</td> 90 120 </tr> -
trunk/language/en_UK/admin.lang.php
r10538 r10552 826 826 $lang['Please wait...'] = 'Please wait...'; 827 827 $lang['Ignore All'] = 'Ignore All'; 828 $lang['Crop'] = 'Crop'; 829 $lang['Width'] = 'Width'; 830 $lang['Height'] = 'Height'; 831 $lang['Follow Orientation'] = 'Follow Orientation'; 828 832 ?> -
trunk/language/fr_FR/admin.lang.php
r10538 r10552 835 835 $lang['Unable to dump database.'] = 'Impossible de sauvegarder la base de données.'; 836 836 $lang['Some upgrades are available for extensions.'] = 'Des mises à jour sont disponibles pour les extensions.'; 837 $lang['Please wait...'] = ' Please wait...';837 $lang['Please wait...'] = 'Veuillez patienter...'; 838 838 $lang['Ignore All'] = 'Tout ignorer'; 839 $lang['Crop'] = 'Retailler'; 840 $lang['Width'] = 'Largeur'; 841 $lang['Height'] = 'Hauteur'; 842 $lang['Follow Orientation'] = "Respecter l'orientation"; 839 843 ?>
Note: See TracChangeset
for help on using the changeset viewer.