2012-05-28 08:01:33 +03:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* COPS (Calibre OPDS PHP Server)
|
|
|
|
|
*
|
|
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
|
|
|
|
* @author Gordon Page <gordon@incero.com> with integration/modification by S<EFBFBD>bastien Lucas <sebastien@slucas.fr>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
require_once ("config.php");
|
2012-05-28 08:05:05 +03:00
|
|
|
|
require_once ("book.php");
|
2012-07-01 15:24:54 +03:00
|
|
|
|
require_once ("data.php");
|
2012-05-28 08:01:33 +03:00
|
|
|
|
|
|
|
|
|
global $config;
|
2012-05-28 08:06:12 +03:00
|
|
|
|
$expires = 60*60*24*14;
|
|
|
|
|
header("Pragma: public");
|
|
|
|
|
header("Cache-Control: maxage=".$expires);
|
|
|
|
|
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
|
2012-06-24 09:16:47 +03:00
|
|
|
|
$bookId = getURLParam ("id", NULL);
|
2012-05-28 08:05:05 +03:00
|
|
|
|
$type = getURLParam ("type", "jpg");
|
2012-06-23 23:11:13 +03:00
|
|
|
|
$idData = getURLParam ("data", NULL);
|
2012-06-24 09:16:47 +03:00
|
|
|
|
if (is_null ($bookId))
|
|
|
|
|
{
|
|
|
|
|
$book = Book::getBookByDataId($idData);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$book = Book::getBookById($bookId);
|
|
|
|
|
}
|
2012-05-28 08:01:33 +03:00
|
|
|
|
|
|
|
|
|
switch ($type)
|
|
|
|
|
{
|
|
|
|
|
case "jpg":
|
|
|
|
|
header("Content-type: image/jpeg");
|
|
|
|
|
if (isset($_GET["width"]))
|
|
|
|
|
{
|
|
|
|
|
$file = $book->getFilePath ($type);
|
|
|
|
|
// get image size
|
|
|
|
|
if($size = GetImageSize($file)){
|
|
|
|
|
$w = $size[0];
|
|
|
|
|
$h = $size[1];
|
|
|
|
|
//set new size
|
|
|
|
|
$nw = $_GET["width"];
|
|
|
|
|
$nh = ($nw*$h)/$w;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
//set new size
|
|
|
|
|
$nw = "160";
|
|
|
|
|
$nh = "120";
|
|
|
|
|
}
|
|
|
|
|
//draw the image
|
|
|
|
|
$src_img = imagecreatefromjpeg($file);
|
|
|
|
|
$dst_img = imagecreatetruecolor($nw,$nh);
|
|
|
|
|
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);//resizing the image
|
2012-07-01 16:23:28 +03:00
|
|
|
|
imagejpeg($dst_img,null,100);
|
2012-05-28 08:01:33 +03:00
|
|
|
|
imagedestroy($src_img);
|
|
|
|
|
imagedestroy($dst_img);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-05-28 08:06:12 +03:00
|
|
|
|
if (isset($_GET["height"]))
|
|
|
|
|
{
|
|
|
|
|
$file = $book->getFilePath ($type);
|
|
|
|
|
// get image size
|
|
|
|
|
if($size = GetImageSize($file)){
|
|
|
|
|
$w = $size[0];
|
|
|
|
|
$h = $size[1];
|
|
|
|
|
//set new size
|
|
|
|
|
$nh = $_GET["height"];
|
|
|
|
|
$nw = ($nh*$w)/$h;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
//set new size
|
|
|
|
|
$nw = "160";
|
|
|
|
|
$nh = "120";
|
|
|
|
|
}
|
|
|
|
|
//draw the image
|
|
|
|
|
$src_img = imagecreatefromjpeg($file);
|
|
|
|
|
$dst_img = imagecreatetruecolor($nw,$nh);
|
|
|
|
|
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);//resizing the image
|
2012-07-01 16:23:28 +03:00
|
|
|
|
imagejpeg($dst_img,null,100);
|
2012-05-28 08:06:12 +03:00
|
|
|
|
imagedestroy($src_img);
|
|
|
|
|
imagedestroy($dst_img);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-05-28 08:01:33 +03:00
|
|
|
|
break;
|
2012-05-28 08:05:05 +03:00
|
|
|
|
default:
|
2012-07-01 15:24:54 +03:00
|
|
|
|
header("Content-type: " . Data::$mimetypes[$type]);
|
2012-05-28 08:01:33 +03:00
|
|
|
|
break;
|
|
|
|
|
}
|
2012-06-23 23:11:13 +03:00
|
|
|
|
$file = $book->getFilePath ($type, $idData, true);
|
2012-11-10 16:10:04 +02:00
|
|
|
|
header('Content-Type: application/octet-stream');
|
|
|
|
|
header('Content-Disposition: attachment; filename="' . basename ($file) . '"');
|
2012-05-28 08:05:05 +03:00
|
|
|
|
header ($config['cops_x_accel_redirect'] . ": " . $config['calibre_internal_directory'] . $file);
|
2012-05-28 08:01:33 +03:00
|
|
|
|
?>
|