Fix: Image always fit into window when using cropping feature even if

file is a very large file.
This commit is contained in:
Laurent Destailleur 2014-03-18 23:24:00 +01:00
parent 3030c2f431
commit ce4c78972a
2 changed files with 62 additions and 48 deletions

View File

@ -1,4 +1,4 @@
// Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net> // Copyright (C) 2009-2014 Laurent Destailleur <eldy@users.sourceforge.net>
// //
// This program is free software; you can redistribute it and/or modify // 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 // 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 // \brief File that include javascript functions for croping feature
// //
/* Enable jcrop plugin onto id cropbox */
jQuery(function() { jQuery(function() {
jQuery('#cropbox').Jcrop({ jQuery('#cropbox').Jcrop({
onSelect: updateCoords, onSelect: updateCoords,
onChange: updateCoords onChange: updateCoords
}); });
}); });
/* Update fields that store new size */
function updateCoords(c) function updateCoords(c)
{ {
jQuery('#x').val(c.x); //alert(parseInt(jQuery("#ratioforcrop").val()));
jQuery('#y').val(c.y); ratio=1;
jQuery('#x2').val(c.x2); if (parseInt(jQuery("#ratioforcrop").val()) > 0) ratio = parseInt(jQuery("#ratioforcrop").val());
jQuery('#y2').val(c.y2); jQuery('#x').val(Math.ceil(c.x * ratio));
jQuery('#w').val(c.w); jQuery('#y').val(Math.ceil(c.y * ratio));
jQuery('#h').val(c.h); 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() function checkCoords()
{ {
if (parseInt(jQuery('#w').val())) return true; if (parseInt(jQuery('#w').val())) return true;

View File

@ -128,11 +128,8 @@ if ($mesg) print '<div class="error">'.$mesg.'</div>';
$infoarray=dol_getImageSize($dir."/".urldecode($_GET["file"])); $infoarray=dol_getImageSize($dir."/".urldecode($_GET["file"]));
$height=$infoarray['height']; $height=$infoarray['height'];
$width=$infoarray['width']; $width=$infoarray['width'];
print $langs->trans("CurrentInformationOnImage").':'; print $langs->trans("CurrentInformationOnImage").': ';
print '<ul> print $langs->trans("Width").': <strong>'.$width.'</strong> x '.$langs->trans("Height").': <strong>'.$height.'</strong><br>';
<li>'.$langs->trans("Width").': '.$width.' px</li>
<li>'.$langs->trans("Height").': '.$height.' px</li>
</ul>';
print '<br>'."\n"; print '<br>'."\n";
@ -142,55 +139,66 @@ print '<form name="redim_file" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" meth
print '<fieldset id="redim_file">'; print '<fieldset id="redim_file">';
print '<legend>'.$langs->trans("Resize").'</legend>'; print '<legend>'.$langs->trans("Resize").'</legend>';
print $langs->trans("ResizeDesc").'<br>'; print $langs->trans("ResizeDesc").'<br>';
print $langs->trans("NewLength").': <input class="flat" name="sizex" size="10" type="text" > px <br> '; print $langs->trans("NewLength").': <input class="flat" name="sizex" size="10" type="text" > px &nbsp; '.$langs->trans("or").' &nbsp; ';
print $langs->trans("NewHeight").': <input class="flat" name="sizey" size="10" type="text" > px &nbsp; <br>'; print $langs->trans("NewHeight").': <input class="flat" name="sizey" size="10" type="text" > px &nbsp; <br>';
print '<input type="hidden" name="file" value="'.$_GET['file'].'" />'; print '<input type="hidden" name="file" value="'.$_GET['file'].'" />';
print '<input type="hidden" name="action" value="confirm_resize" />'; print '<input type="hidden" name="action" value="confirm_resize" />';
print '<input type="hidden" name="product" value="'.$id.'" />'; print '<input type="hidden" name="product" value="'.$id.'" />';
print '<input type="hidden" name="id" value="'.$id.'" />'; print '<input type="hidden" name="id" value="'.$id.'" />';
print '<br><input class="button" name="sendit" value="'.dol_escape_htmltag($langs->trans("Resize")).'" type="submit" />'; print '<br><input class="button" name="sendit" value="'.dol_escape_htmltag($langs->trans("Resize")).'" type="submit" />';
print '</fieldset>'; print '</fieldset>'."\n";
print '<br></form>'; print '</form>';
print '<br>'."\n";
/* /*
* Recadrage d'une image * Crop image
*/ */
print '<br>'."\n"; print '<br>'."\n";
if (! empty($conf->use_javascript_ajax)) if (! empty($conf->use_javascript_ajax))
{ {
$infoarray=dol_getImageSize($dir."/".urldecode($_GET["file"]));
$infoarray=dol_getImageSize($dir."/".urldecode($_GET["file"])); $height=$infoarray['height'];
$height=$infoarray['height']; $width=$infoarray['width'];
$width=$infoarray['width']; $widthforcrop=$width; $refsizeforcrop='orig'; $ratioforcrop=1;
if (! empty($_SESSION['dol_screenwidth']) && ($widthforcrop > round($_SESSION['dol_screenwidth']/2)))
print '<!-- Form to crop -->'."\n"; {
print '<fieldset id="redim_file">'; $widthforcrop=min(round($_SESSION['dol_screenwidth']/2),$widthforcrop);
print '<legend>'.$langs->trans("Recenter").'</legend>'; $refsizeforcrop='screenwidth';
print $langs->trans("DefineNewAreaToPick").'...<br>'; $ratioforcrop=2;
print '<br><center>'; }
print '<div style="border: 1px solid #888888; width: '.$width.'px;"><img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$object->entity.'&file='.$original_file.'" alt="" id="cropbox" /></div>';
print '</center><br>'; print '<!-- Form to crop -->'."\n";
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post" onsubmit="return checkCoords();"> print '<fieldset id="redim_file">';
<div class="jc_coords"> print '<legend>'.$langs->trans("Recenter").'</legend>';
'.$langs->trans("NewSizeAfterCropping").': print $langs->trans("DefineNewAreaToPick").'...<br>';
<label>X1 <input type="text" size="4" id="x" name="x" /></label> print '<br><center>';
<label>Y1 <input type="text" size="4" id="y" name="y" /></label> print '<div style="border: 1px solid #888888; width: '.$widthforcrop.'px;">';
<label>X2 <input type="text" size="4" id="x2" name="x2" /></label> print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$object->entity.'&file='.$original_file.'" alt="" id="cropbox" width="'.$widthforcrop.'px"/>';
<label>Y2 <input type="text" size="4" id="y2" name="y2" /></label> print '</div>';
<label>W <input type="text" size="4" id="w" name="w" /></label> print '</center><br>';
<label>H <input type="text" size="4" id="h" name="h" /></label> print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post" onsubmit="return checkCoords();">
</div> <div class="jc_coords">
'.$langs->trans("NewSizeAfterCropping").':
<input type="hidden" id="file" name="file" value="'.urlencode($original_file).'" /> <label>X1 <input type="text" size="4" id="x" name="x" /></label>
<input type="hidden" id="action" name="action" value="confirm_crop" /> <label>Y1 <input type="text" size="4" id="y" name="y" /></label>
<input type="hidden" id="product" name="product" value="'.$id.'" /> <label>X2 <input type="text" size="4" id="x2" name="x2" /></label>
<input type="hidden" name="id" value="'.$id.'" /> <label>Y2 <input type="text" size="4" id="y2" name="y2" /></label>
<br><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Recenter")).'" /> <label>W <input type="text" size="4" id="w" name="w" /></label>
</form>'; <label>H <input type="text" size="4" id="h" name="h" /></label>
print '</fieldset>'; </div>
<input type="hidden" id="file" name="file" value="'.urlencode($original_file).'" />
<input type="hidden" id="action" name="action" value="confirm_crop" />
<input type="hidden" id="product" name="product" value="'.$id.'" />
<input type="hidden" id="refsizeforcrop" name="refsizeforcrop" value="'.$refsizeforcrop.'" />
<input type="hidden" id="ratioforcrop" name="ratioforcrop" value="'.$ratioforcrop.'" />
<input type="hidden" name="id" value="'.$id.'" />
<br><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Recenter")).'" />
</form>'."\n";
print '</fieldset>'."\n";
print '<br>';
} }