78 lines
2.0 KiB
PHP
78 lines
2.0 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 14/gen/2016
|
|
*/
|
|
|
|
require_once(dirname(__FILE__)."/load.php");
|
|
|
|
// $sizes = array(
|
|
// "large"=>array("width"=>800,"height"=>600),
|
|
// "small"=>array("width"=>160,"height"=>120)
|
|
// );
|
|
|
|
if (array_key_exists("id",$_GET)) {
|
|
$size = MediaImage::SIZE_ORIGINAL;
|
|
if (array_key_exists('size',$_GET) && array_key_exists(intval($_GET["size"]), MediaImage::$SIZES)){
|
|
$size=intval($_GET['size']);
|
|
}
|
|
|
|
if ($size == 3){
|
|
if (!ImageCacheManager::isCached($_GET["id"], $size)){
|
|
$img = GlobalVariables::get("dao")->getFirst("MediaModel",array("id"=>$_GET['id']));
|
|
if (!is_null($img)){
|
|
ImageCacheManager::cacheImage($img, $size);
|
|
}
|
|
else {
|
|
die();
|
|
}
|
|
}
|
|
ImageCacheManager::printCachedMedia($_GET["id"], $size);
|
|
}
|
|
else {
|
|
$img = GlobalVariables::get("dao")->getFirst("MediaModel",array("id"=>$_GET['id']));
|
|
|
|
if (!is_null($img)){
|
|
$basepath = GlobalVariables::get("config")->paths->media;
|
|
$toMime = $basepath."/".$img->id.".".$img->extension;
|
|
$thumb = new Imagick($basepath."/".$img->id.".".$img->extension);
|
|
|
|
$geom = $thumb->getimagegeometry();
|
|
|
|
if($img->extension != "gif"){
|
|
if ($size!=MediaImage::SIZE_ORIGINAL){
|
|
if ($geom["width"]>=$geom["height"]){
|
|
$thumb->scaleimage(MediaImage::$SIZES[$size]["width"], 0,false);
|
|
}
|
|
else {
|
|
$thumb->scaleimage(0, MediaImage::$SIZES[$size]["height"],false);
|
|
}
|
|
}
|
|
|
|
header('Content-type: '.mime_content_type($toMime));
|
|
echo $thumb;
|
|
}
|
|
else{
|
|
|
|
$thumb = $thumb->coalesceimages();
|
|
if ($size!=MediaImage::SIZE_ORIGINAL){
|
|
foreach ($thumb as $frame){
|
|
if ($geom["width"]>=$geom["height"]){
|
|
$thumb->scaleimage(MediaImage::$SIZES[$size]["width"], 0,false);
|
|
}
|
|
else {
|
|
$thumb->scaleimage(0, MediaImage::$SIZES[$size]["height"],false);
|
|
}
|
|
}
|
|
}
|
|
$thumb = $thumb->deconstructimages();
|
|
|
|
header('Content-type: '.mime_content_type($toMime));
|
|
echo $thumb->getimagesblob();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|