Add caching to gallery thumbnail generation
This commit is contained in:
parent
eb5de4d4f7
commit
43d2266f5c
|
@ -25,22 +25,14 @@ require_once('../../../lib/base.php');
|
|||
OC_JSON::checkLoggedIn();
|
||||
OC_JSON::checkAppEnabled('gallery');
|
||||
|
||||
$box_size = 200;
|
||||
$img = $_GET['img'];
|
||||
|
||||
$imagePath = OC_Filesystem::getLocalFile($img);
|
||||
|
||||
if(file_exists($imagePath)) {
|
||||
$image = new OC_Image($imagePath);
|
||||
$image->centerCrop();
|
||||
$image->resize($box_size, $box_size);
|
||||
$image->fixOrientation();
|
||||
|
||||
$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');
|
||||
|
||||
$image->show();
|
||||
$image = OC_Gallery_Photo::getThumbnail($img);
|
||||
if ($image) {
|
||||
$offset = 3600 * 24; // 24 hour
|
||||
// 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');
|
||||
$image->show();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class OC_Gallery_Photo{
|
||||
class OC_Gallery_Photo {
|
||||
public static function create($albumId, $img){
|
||||
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)');
|
||||
$stmt->execute(array($albumId, $img));
|
||||
|
@ -65,5 +65,34 @@ class OC_Gallery_Photo{
|
|||
$stmt = OC_DB::prepare("UPDATE *PREFIX*gallery_photos SET file_path = ?, album_id = ? WHERE album_id = ? and file_path = ?");
|
||||
$stmt->execute(array($newpath, $newAlbumId, $oldAlbumId, $oldpath));
|
||||
}
|
||||
}
|
||||
|
||||
public static function getThumbnail($image_name) {
|
||||
$imagePath = OC_Filesystem::getLocalFile($image_name);
|
||||
if(!file_exists($imagePath)) {
|
||||
return null;
|
||||
}
|
||||
$save_dir = OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/';
|
||||
$save_dir .= dirname($image_name). '/';
|
||||
$image_name = basename($image_name);
|
||||
$thumb_file = $save_dir . $image_name;
|
||||
if (file_exists($thumb_file)) {
|
||||
$image = new OC_Image($thumb_file);
|
||||
} else {
|
||||
$image = new OC_Image($imagePath);
|
||||
if ($image->valid()) {
|
||||
$image->centerCrop();
|
||||
$image->resize(200);
|
||||
$image->fixOrientation();
|
||||
if (!is_dir($save_dir)) {
|
||||
mkdir($save_dir, 0777, true);
|
||||
}
|
||||
$image->save($thumb_file);
|
||||
}
|
||||
}
|
||||
if ($image->valid()) {
|
||||
//var_dump($image, $image->resource());
|
||||
return $image;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue