Files
fdn2/public/getImage.php
T
2016-03-04 12:26:30 +01:00

63 lines
1.6 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']);
}
$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();
}
}
}
?>