FIX croping function
This commit is contained in:
parent
0c82577fc5
commit
0d8cf96f8f
@ -32,12 +32,40 @@ function updateCoords(c)
|
|||||||
{
|
{
|
||||||
//alert(parseInt(jQuery("#ratioforcrop").val()));
|
//alert(parseInt(jQuery("#ratioforcrop").val()));
|
||||||
ratio=1;
|
ratio=1;
|
||||||
if (parseInt(jQuery("#ratioforcrop").val()) > 0) ratio = parseInt(jQuery("#ratioforcrop").val());
|
imagewidth=0;
|
||||||
|
imageheight=0;
|
||||||
|
|
||||||
|
console.log(c);
|
||||||
|
|
||||||
|
if (parseInt(jQuery("#ratioforcrop").val()) > 1) {
|
||||||
|
ratio = parseInt(jQuery("#ratioforcrop").val());
|
||||||
|
if (parseInt(jQuery("#imagewidth").val()) > 0) imagewidth = parseInt(jQuery("#imagewidth").val());
|
||||||
|
if (parseInt(jQuery("#imageheight").val()) > 0) imageheight = parseInt(jQuery("#imageheight").val());
|
||||||
|
}
|
||||||
|
|
||||||
|
x = Math.floor(c.x * ratio);
|
||||||
|
y = Math.floor(c.y * ratio);
|
||||||
|
x2 = Math.ceil(c.x2 * ratio);
|
||||||
|
y2 = Math.ceil(c.y2 * ratio);
|
||||||
|
console.log("x="+x+" y="+y+" x2="+x2+" y2="+y2+" imageheight="+imageheight+" ratio="+ratio);
|
||||||
|
if (imagewidth > 0 && x > imagewidth) {
|
||||||
|
x = imagewidth;
|
||||||
|
}
|
||||||
|
if (imageheight > 0 && y > imageheight) {
|
||||||
|
y = imageheight;
|
||||||
|
}
|
||||||
|
if (imagewidth > 0 && x2 > imagewidth) {
|
||||||
|
x2 = imagewidth;
|
||||||
|
}
|
||||||
|
if (imageheight > 0 && y2 > imageheight) {
|
||||||
|
y2 = imageheight;
|
||||||
|
}
|
||||||
|
|
||||||
//console.log(ratio);
|
//console.log(ratio);
|
||||||
jQuery('#x').val(Math.ceil(c.x * ratio));
|
jQuery('#x').val(x);
|
||||||
jQuery('#y').val(Math.ceil(c.y * ratio));
|
jQuery('#y').val(y);
|
||||||
jQuery('#x2').val(Math.ceil(c.x2 * ratio));
|
jQuery('#x2').val(x2);
|
||||||
jQuery('#y2').val(Math.ceil(c.y2 * ratio));
|
jQuery('#y2').val(y2);
|
||||||
jQuery('#w').val(Math.ceil(c.w * ratio));
|
jQuery('#w').val(x2-x);
|
||||||
jQuery('#h').val(Math.ceil(c.h * ratio));
|
jQuery('#h').val(y2-y);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -536,11 +536,16 @@ if (!empty($conf->use_javascript_ajax)) {
|
|||||||
$widthforcrop = $width;
|
$widthforcrop = $width;
|
||||||
$refsizeforcrop = 'orig';
|
$refsizeforcrop = 'orig';
|
||||||
$ratioforcrop = 1;
|
$ratioforcrop = 1;
|
||||||
|
|
||||||
// If image is too large, we use another scale.
|
// If image is too large, we use another scale.
|
||||||
if (!empty($_SESSION['dol_screenwidth']) && ($widthforcrop > round($_SESSION['dol_screenwidth'] / 2))) {
|
if (!empty($_SESSION['dol_screenwidth'])) {
|
||||||
$ratioforcrop = 2;
|
$widthforcroporigin = $widthforcrop;
|
||||||
$widthforcrop = round($_SESSION['dol_screenwidth'] / $ratioforcrop);
|
while ($widthforcrop > round($_SESSION['dol_screenwidth'] / 1.5)) {
|
||||||
$refsizeforcrop = 'screenwidth';
|
//var_dump($widthforcrop.' '.round($_SESSION['dol_screenwidth'] / 1.5));
|
||||||
|
$ratioforcrop = 2 * $ratioforcrop;
|
||||||
|
$widthforcrop = floor($widthforcroporigin / $ratioforcrop);
|
||||||
|
$refsizeforcrop = 'screenwidth';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print '<!-- Form to crop -->'."\n";
|
print '<!-- Form to crop -->'."\n";
|
||||||
@ -571,8 +576,11 @@ if (!empty($conf->use_javascript_ajax)) {
|
|||||||
<input type="hidden" id="file" name="file" value="'.dol_escape_htmltag($original_file).'" />
|
<input type="hidden" id="file" name="file" value="'.dol_escape_htmltag($original_file).'" />
|
||||||
<input type="hidden" id="action" name="action" value="confirm_crop" />
|
<input type="hidden" id="action" name="action" value="confirm_crop" />
|
||||||
<input type="hidden" id="product" name="product" value="'.dol_escape_htmltag($id).'" />
|
<input type="hidden" id="product" name="product" value="'.dol_escape_htmltag($id).'" />
|
||||||
|
<input type="hidden" id="dol_screenwidth" name="dol_screenwidth" value="'.$_SESSION['dol_screenwidth'].'" />
|
||||||
<input type="hidden" id="refsizeforcrop" name="refsizeforcrop" value="'.$refsizeforcrop.'" />
|
<input type="hidden" id="refsizeforcrop" name="refsizeforcrop" value="'.$refsizeforcrop.'" />
|
||||||
<input type="hidden" id="ratioforcrop" name="ratioforcrop" value="'.$ratioforcrop.'" /><!-- field used by core/lib/lib_photoresize.js -->
|
<input type="hidden" id="ratioforcrop" name="ratioforcrop" value="'.$ratioforcrop.'" /><!-- value in field used by js/lib/lib_photoresize.js -->
|
||||||
|
<input type="hidden" id="imagewidth" name="imagewidth" value="'.$width.'" /><!-- value in field used by js/lib/lib_photoresize.js -->
|
||||||
|
<input type="hidden" id="imageheight" name="imageheight" value="'.$height.'" /><!-- value in field used by js/lib/lib_photoresize.js -->
|
||||||
<input type="hidden" name="modulepart" value="'.dol_escape_htmltag($modulepart).'" />
|
<input type="hidden" name="modulepart" value="'.dol_escape_htmltag($modulepart).'" />
|
||||||
<input type="hidden" name="id" value="'.dol_escape_htmltag($id).'" />
|
<input type="hidden" name="id" value="'.dol_escape_htmltag($id).'" />
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user