Skip to content

Commit

Permalink
Move a not used function into a better place.
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Apr 9, 2016
1 parent d395e8b commit acf546d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 38 deletions.
40 changes: 2 additions & 38 deletions htdocs/core/class/fileupload.class.php
Expand Up @@ -375,7 +375,7 @@ protected function upcountName($name)
}

/**
* Enter description here ...
* trimFileName
*
* @param string $name Filename
* @param string $type ???
Expand Down Expand Up @@ -404,43 +404,7 @@ protected function trimFileName($name, $type, $index)
}

/**
* Enter description here ...
*
* @param unknown_type $file_path ???
* @return boolean Success or not
*/
protected function orientImage($file_path)
{
$exif = @exif_read_data($file_path);
if ($exif === false) {
return false;
}
$orientation = intval(@$exif['Orientation']);
if (!in_array($orientation, array(3, 6, 8))) {
return false;
}
$image = @imagecreatefromjpeg($file_path);
switch ($orientation) {
case 3:
$image = @imagerotate($image, 180, 0);
break;
case 6:
$image = @imagerotate($image, 270, 0);
break;
case 8:
$image = @imagerotate($image, 90, 0);
break;
default:
return false;
}
$success = imagejpeg($image, $file_path);
// Free up memory (imagedestroy does not delete files):
@imagedestroy($image);
return $success;
}

/**
* Enter description here ...
* handleFileUpload
*
* @param string $uploaded_file Uploade file
* @param string $name Name
Expand Down
40 changes: 40 additions & 0 deletions htdocs/core/lib/images.lib.php
Expand Up @@ -291,6 +291,46 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x=0, $s
}


/**
* dolRotateImage if image is a jpg file.
* Currently use an autodetection to know if we can rotate.
* TODO Introduce a new parameter to force rotate.
*
* @param string $file_path Full path to image to rotate
* @return boolean Success or not
*/
function dolRotateImage($file_path)
{
$exif = @exif_read_data($file_path);
if ($exif === false) {
return false;
}
$orientation = intval(@$exif['Orientation']);
if (!in_array($orientation, array(3, 6, 8))) {
return false;
}
$image = @imagecreatefromjpeg($file_path);
switch ($orientation) {
case 3:
$image = @imagerotate($image, 180, 0);
break;
case 6:
$image = @imagerotate($image, 270, 0);
break;
case 8:
$image = @imagerotate($image, 90, 0);
break;
default:
return false;
}
$success = imagejpeg($image, $file_path);
// Free up memory (imagedestroy does not delete files):
@imagedestroy($image);
return $success;
}



/**
* Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
* If file is myfile.jpg, new file may be myfile_small.jpg
Expand Down

0 comments on commit acf546d

Please sign in to comment.