From e1e57f52ad7aacee979ff1e14708c84648b306cb Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Sun, 21 Feb 2010 03:09:45 +0000
Subject: [PATCH] New: Add feature to crop/resize image file on product photos
---
htdocs/{product => core}/photos_resize.php | 63 +++---
htdocs/core/pre.inc.php | 41 ++++
.../barcode/html.formbarcode.class.php | 2 +-
htdocs/langs/en_US/other.lang | 5 +
htdocs/langs/fr_FR/other.lang | 5 +
htdocs/lib/images.lib.php | 211 ++++++++++++++++--
htdocs/product.class.php | 12 +-
htdocs/product/barcode.php | 5 +-
htdocs/product/pre.inc.php | 2 +-
9 files changed, 292 insertions(+), 54 deletions(-)
rename htdocs/{product => core}/photos_resize.php (62%)
create mode 100644 htdocs/core/pre.inc.php
diff --git a/htdocs/product/photos_resize.php b/htdocs/core/photos_resize.php
similarity index 62%
rename from htdocs/product/photos_resize.php
rename to htdocs/core/photos_resize.php
index 68d6e8d7382..aacd0c548b7 100644
--- a/htdocs/product/photos_resize.php
+++ b/htdocs/core/photos_resize.php
@@ -34,7 +34,7 @@ if (isset($_GET["id"]))
$result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid);
-$original_file = isset($_GET["file"])?urldecode($_GET["file"]):'';
+$original_file = isset($_REQUEST["file"])?urldecode($_REQUEST["file"]):'';
$langs->load("products");
@@ -46,32 +46,28 @@ if (!$user->rights->produit->lire) accessforbidden();
* Actions
*/
-if ($_POST["action"] == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POST["sizex"]) != "") &&(isset($_POST["sizey"]) != ""))
+if ($_POST["action"] == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POST["sizex"]) != "") && (isset($_POST["sizey"]) != ""))
{
-/* $thumb = new Imagick($conf->produit->dir_output."/".$_POST["file"]);
- $height=$thumb->getImageHeight(); // dimensions de l'image actuelle
- $width=$thumb->getImageWidth(); // dimensions de l'image actuelle
+ $fullpath=$conf->produit->dir_output."/".$_POST["file"];
+ $result=dol_imageResize($fullpath,$_POST['sizex'],$_POST['sizey']);
- if($_POST["sizex"] != "")
+ if ($result == $fullpath)
{
- if ($width > $_POST['sizex'])
- $thumb->scaleImage(intval($_POST['sizex']), 0);
+ header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$_POST["product"].'&action=addthumb&file='.urldecode($_POST["file"]));
+ exit;
}
- if($_POST["sizey"] != "")
+ else
{
- if ($height > $_POST['sizey'])
- $thumb->scaleImage(0, intval($_POST['sizey']));
+ $mesg=$result;
+ $_GET['file']=$_POST["file"];
+ $_GET['id']=$_POST["id"];
}
- $thumb->writeImage($conf->produit->dir_output."/".$_POST["file"]);
- $thumb->destroy();
-*/
- header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$_POST["product"].'&action=addthumb&file='.urldecode($_POST["file"]));
- exit;
}
// Crop d'une image
if ($_POST["action"] == 'confirm_crop' && $_POST["file"])
{
+ // TODO Add function to crop image in images.lib.php
/* $thumb = new Imagick($conf->produit->dir_output."/".urldecode($_POST["file"]));
$thumb->cropImage($_POST['w'], $_POST['h'], $_POST['x'], $_POST['y']);
$thumb->writeImage($conf->produit->dir_output."/".urldecode($_POST["file"]));
@@ -86,31 +82,35 @@ if ($_POST["action"] == 'confirm_crop' && $_POST["file"])
* View
*/
-llxHeader($head, $langs->trans("Resize"), '', '', 0, 0, array('includes/jcrop/js/jquery.min.js','includes/jcrop/js/jquery.Jcrop.min.js','lib/lib_photosresize.js'), array(DOL_URL_ROOT.'/includes/jcrop/css/jquery.Jcrop.css'));
+llxHeader($head, $langs->trans("Image"), '', '', 0, 0, array('includes/jcrop/js/jquery.min.js','includes/jcrop/js/jquery.Jcrop.min.js','lib/lib_photosresize.js'), array(DOL_URL_ROOT.'/includes/jcrop/css/jquery.Jcrop.css'));
-print_fiche_titre($langs->trans("Current"));
+print_fiche_titre($langs->trans("Image"));
+
+if ($mesg) print ''.$mesg.'
';
$infoarray=dol_getImageSize($conf->produit->dir_output."/".urldecode($_GET["file"]));
$height=$infoarray['height'];
$width=$infoarray['width'];
print $langs->trans("Size").':
- - '.$langs->trans("Length").': '.$width.' px
- - '.$langs->trans("Width").': '.$height.' px
+ - '.$langs->trans("Width").': '.$width.' px
+ - '.$langs->trans("Height").': '.$height.' px
';
print '
';
print_fiche_titre($langs->trans("Resize"),'','');
-print '';
print '
';
@@ -121,14 +121,16 @@ print '
';
print '
';
print_fiche_titre($langs->trans("Recenter"),'','');
-print 'Define new area to keep...
';
-print '
';
+print $langs->trans("DefineNewAreaToPick").'...
';
+print '
';
+print '
';
+print '
';
$infoarray=dol_getImageSize($conf->produit->dir_output."/".urldecode($_GET["file"]));
$height=$infoarray['height'];
$width=$infoarray['width'];
-print '