]> source.dussan.org Git - nextcloud-server.git/commitdiff
Contacts: Fix error on photo crop.
authorThomas Tanghus <thomas@tanghus.net>
Sat, 21 Apr 2012 23:50:46 +0000 (01:50 +0200)
committerThomas Tanghus <thomas@tanghus.net>
Sat, 21 Apr 2012 23:50:46 +0000 (01:50 +0200)
apps/contacts/ajax/savecrop.php

index 0df4e1998cba0630765198c0b08745ee76df990f..73ac521e04bf0331cf7e2cc9a7c9c527131ff104 100644 (file)
@@ -44,19 +44,15 @@ function bailOut($msg) {
 
 $image = null;
 
-$x1 = (isset($_POST['x1']) && $_POST['x1']) ? $_POST['x1'] : -1;
+$x1 = (isset($_POST['x1']) && $_POST['x1']) ? $_POST['x1'] : 0;
 //$x2 = isset($_POST['x2']) ? $_POST['x2'] : -1;
-$y1 = (isset($_POST['y1']) && $_POST['y1']) ? $_POST['y1'] : -1;
+$y1 = (isset($_POST['y1']) && $_POST['y1']) ? $_POST['y1'] : 0;
 //$y2 = isset($_POST['y2']) ? $_POST['y2'] : -1;
 $w = (isset($_POST['w']) && $_POST['w']) ? $_POST['w'] : -1;
 $h = (isset($_POST['h']) && $_POST['h']) ? $_POST['h'] : -1;
 $tmp_path = isset($_POST['tmp_path']) ? $_POST['tmp_path'] : '';
 $id = isset($_POST['id']) ? $_POST['id'] : '';
 
-if(in_array(-1, array($x1, $y1, $w, $h))) {
-       bailOut('Wrong crop dimensions: '.implode(', ', array($x1, $y1, $w, $h)));
-}
-
 if($tmp_path == '') {
        bailOut('Missing path to temporary file.');
 }
@@ -70,6 +66,9 @@ OC_Log::write('contacts','savecrop.php: files: '.$tmp_path.'  exists: '.file_exi
 if(file_exists($tmp_path)) {
        $image = new OC_Image();
        if($image->loadFromFile($tmp_path)) {
+               $w = ($w != -1 ? $w : $image->width());
+               $h = ($h != -1 ? $h : $image->height());
+               OC_Log::write('contacts','savecrop.php, x: '.$x1.' y: '.$y1.' w: '.$w.' h: '.$h, OC_Log::DEBUG);
                if($image->crop($x1, $y1, $w, $h)) {
                        if($image->resize(200)) {
                                $tmpfname = tempnam("/tmp", "occCropped"); // create a new file because of caching issues.
@@ -81,7 +80,7 @@ if(file_exists($tmp_path)) {
                                                bailOut('Error getting contact object.');
                                        }
                                        if($card->__isset('PHOTO')) {
-                                               OC_Log::write('contacts','savecrop.php: files: PHOTO property exists.', OC_Log::DEBUG);
+                                               OC_Log::write('contacts','savecrop.php: PHOTO property exists.', OC_Log::DEBUG);
                                                $property = $card->__get('PHOTO');
                                                if(!$property) {
                                                        unlink($tmpfname);