From ce4c78972af32ce47f8ac535e03f23e2b25f1a12 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 18 Mar 2014 23:24:00 +0100 Subject: [PATCH] Fix: Image always fit into window when using cropping feature even if file is a very large file. --- htdocs/core/js/lib_photosresize.js | 22 +++++--- htdocs/core/photos_resize.php | 88 ++++++++++++++++-------------- 2 files changed, 62 insertions(+), 48 deletions(-) diff --git a/htdocs/core/js/lib_photosresize.js b/htdocs/core/js/lib_photosresize.js index 94c7ffa2a33..6847de0bd54 100644 --- a/htdocs/core/js/lib_photosresize.js +++ b/htdocs/core/js/lib_photosresize.js @@ -1,4 +1,4 @@ -// Copyright (C) 2009 Laurent Destailleur +// Copyright (C) 2009-2014 Laurent Destailleur // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -19,23 +19,29 @@ // \brief File that include javascript functions for croping feature // +/* Enable jcrop plugin onto id cropbox */ jQuery(function() { jQuery('#cropbox').Jcrop({ onSelect: updateCoords, onChange: updateCoords }); }); - + +/* Update fields that store new size */ function updateCoords(c) { - jQuery('#x').val(c.x); - jQuery('#y').val(c.y); - jQuery('#x2').val(c.x2); - jQuery('#y2').val(c.y2); - jQuery('#w').val(c.w); - jQuery('#h').val(c.h); + //alert(parseInt(jQuery("#ratioforcrop").val())); + ratio=1; + if (parseInt(jQuery("#ratioforcrop").val()) > 0) ratio = parseInt(jQuery("#ratioforcrop").val()); + jQuery('#x').val(Math.ceil(c.x * ratio)); + jQuery('#y').val(Math.ceil(c.y * ratio)); + jQuery('#x2').val(Math.ceil(c.x2 * ratio)); + jQuery('#y2').val(Math.ceil(c.y2 * ratio)); + jQuery('#w').val(Math.ceil(c.w * ratio)); + jQuery('#h').val(Math.ceil(c.h * ratio)); }; +/* checkCoords */ function checkCoords() { if (parseInt(jQuery('#w').val())) return true; diff --git a/htdocs/core/photos_resize.php b/htdocs/core/photos_resize.php index 4d74a819ebf..b96e0717eab 100644 --- a/htdocs/core/photos_resize.php +++ b/htdocs/core/photos_resize.php @@ -128,11 +128,8 @@ if ($mesg) print '
'.$mesg.'
'; $infoarray=dol_getImageSize($dir."/".urldecode($_GET["file"])); $height=$infoarray['height']; $width=$infoarray['width']; -print $langs->trans("CurrentInformationOnImage").':'; -print '
    -
  • '.$langs->trans("Width").': '.$width.' px
  • -
  • '.$langs->trans("Height").': '.$height.' px
  • -
'; +print $langs->trans("CurrentInformationOnImage").': '; +print $langs->trans("Width").': '.$width.' x '.$langs->trans("Height").': '.$height.'
'; print '
'."\n"; @@ -142,55 +139,66 @@ print '
'; print ''.$langs->trans("Resize").''; print $langs->trans("ResizeDesc").'
'; -print $langs->trans("NewLength").': px
'; +print $langs->trans("NewLength").': px   '.$langs->trans("or").'   '; print $langs->trans("NewHeight").': px  
'; print ''; print ''; print ''; print ''; print '
'; -print ''; -print '
'; +print ''."\n"; +print ''; +print '
'."\n"; /* - * Recadrage d'une image + * Crop image */ print '
'."\n"; if (! empty($conf->use_javascript_ajax)) { - -$infoarray=dol_getImageSize($dir."/".urldecode($_GET["file"])); -$height=$infoarray['height']; -$width=$infoarray['width']; - -print ''."\n"; -print '
'; -print ''.$langs->trans("Recenter").''; -print $langs->trans("DefineNewAreaToPick").'...
'; -print '
'; -print '
'; -print '

'; -print '
-
- '.$langs->trans("NewSizeAfterCropping").': - - - - - - -
- - - - - -
-
'; -print '
'; - + $infoarray=dol_getImageSize($dir."/".urldecode($_GET["file"])); + $height=$infoarray['height']; + $width=$infoarray['width']; + $widthforcrop=$width; $refsizeforcrop='orig'; $ratioforcrop=1; + if (! empty($_SESSION['dol_screenwidth']) && ($widthforcrop > round($_SESSION['dol_screenwidth']/2))) + { + $widthforcrop=min(round($_SESSION['dol_screenwidth']/2),$widthforcrop); + $refsizeforcrop='screenwidth'; + $ratioforcrop=2; + } + + print ''."\n"; + print '
'; + print ''.$langs->trans("Recenter").''; + print $langs->trans("DefineNewAreaToPick").'...
'; + print '
'; + print '
'; + print ''; + print '
'; + print '

'; + print '
+
+ '.$langs->trans("NewSizeAfterCropping").': + + + + + + +
+ + + + + + + +
+
'."\n"; + print '
'."\n"; + print '
'; }