Change gallery thumbnail generation to OC_Image
This commit is contained in:
parent
7c03b612d2
commit
eb5de4d4f7
|
@ -69,7 +69,7 @@ function handlePartialCreate($path) {
|
|||
if (!OC_Filesystem::is_dir($path)) OC_JSON::error(array('cause' => 'Invalid path given'));
|
||||
|
||||
$album = OC_Gallery_Album::find(OC_User::getUser(), null, $path);
|
||||
$albums;
|
||||
$albums = array();
|
||||
OC_Gallery_Scanner::scanDir($path, $albums);
|
||||
OC_JSON::success(array('album_details' => $albums));
|
||||
}
|
||||
|
|
|
@ -25,65 +25,22 @@ require_once('../../../lib/base.php');
|
|||
OC_JSON::checkLoggedIn();
|
||||
OC_JSON::checkAppEnabled('gallery');
|
||||
|
||||
function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height) { //$imgSrc is a FILE - Returns an image resource.
|
||||
//getting the image dimensions
|
||||
if(! function_exists('imagecreatefromjpeg'))
|
||||
OC_Log::write('gallery','GD module not installed',OC_Log::ERROR);
|
||||
|
||||
list($width_orig, $height_orig) = getimagesize($imgSrc);
|
||||
switch (strtolower(substr($imgSrc, strrpos($imgSrc, '.')+1))) {
|
||||
case "jpeg":
|
||||
case "jpg":
|
||||
case "tiff":
|
||||
$myImage = imagecreatefromjpeg($imgSrc);
|
||||
break;
|
||||
case "png":
|
||||
$myImage = imagecreatefrompng($imgSrc);
|
||||
break;
|
||||
default:
|
||||
exit();
|
||||
}
|
||||
if(!$myImage) exit();
|
||||
$ratio_orig = $width_orig/$height_orig;
|
||||
|
||||
if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
|
||||
$new_height = $thumbnail_width/$ratio_orig;
|
||||
$new_width = $thumbnail_width;
|
||||
} else {
|
||||
$new_width = $thumbnail_height*$ratio_orig;
|
||||
$new_height = $thumbnail_height;
|
||||
}
|
||||
|
||||
$x_mid = $new_width/2; //horizontal middle
|
||||
$y_mid = $new_height/2; //vertical middle
|
||||
|
||||
$process = imagecreatetruecolor(round($new_width), round($new_height));
|
||||
|
||||
imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
|
||||
$thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
|
||||
imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
|
||||
|
||||
imagedestroy($process);
|
||||
imagedestroy($myImage);
|
||||
return $thumb;
|
||||
}
|
||||
|
||||
$box_size = 200;
|
||||
$img = $_GET['img'];
|
||||
|
||||
$imagePath = OC_Filesystem::getLocalFile($img);
|
||||
|
||||
if(file_exists($imagePath))
|
||||
{
|
||||
$image = CroppedThumbnail($imagePath, $box_size, $box_size);
|
||||
if(file_exists($imagePath)) {
|
||||
$image = new OC_Image($imagePath);
|
||||
$image->centerCrop();
|
||||
$image->resize($box_size, $box_size);
|
||||
$image->fixOrientation();
|
||||
|
||||
header('Content-Type: image/png');
|
||||
$offset = 3600 * 24;
|
||||
// calc the string in GMT not localtime and add the offset
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
|
||||
header('Cache-Control: max-age='.$offset.', must-revalidate');
|
||||
header('Pragma: public');
|
||||
|
||||
imagepng($image);
|
||||
imagedestroy($image);
|
||||
$image->show();
|
||||
}
|
||||
|
|
|
@ -147,6 +147,10 @@ class OC_Image {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (!$this->valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$retval = false;
|
||||
switch(self::$imagetype) {
|
||||
case IMAGETYPE_GIF:
|
||||
|
@ -257,7 +261,7 @@ class OC_Image {
|
|||
$flip = true;
|
||||
break;
|
||||
case 8:
|
||||
$rotate = 270;
|
||||
$rotate = 90;
|
||||
$flip = false;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ class OC_Util {
|
|||
/**
|
||||
* @brief Add a custom element to the header
|
||||
* @param string tag tag name of the element
|
||||
* @param array $attributes array of attrobutes for the element
|
||||
* @param array $attributes array of attributes for the element
|
||||
* @param string $text the text content for the element
|
||||
*/
|
||||
public static function addHeader( $tag, $attributes, $text=''){
|
||||
|
|
Loading…
Reference in New Issue