Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...) http://blog.slucas.fr/en/oss/calibre-opds-php-server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.8KB

  1. <?php
  2. /**
  3. * COPS (Calibre OPDS PHP Server)
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Gordon Page <gordon@incero.com> with integration/modification by Sébastien Lucas <sebastien@slucas.fr>
  7. */
  8. require_once ("config.php");
  9. require_once('book.php');
  10. global $config;
  11. $bookId = $_GET["id"];
  12. $book = Book::getBookById($bookId);
  13. $type = "jpg";
  14. if (!empty ($_GET) && isset($_GET["type"])) {
  15. $type = $_GET["type"];
  16. }
  17. switch ($type)
  18. {
  19. case "jpg":
  20. header("Content-type: image/jpeg");
  21. if (isset($_GET["width"]))
  22. {
  23. $file = $book->getFilePath ($type);
  24. // get image size
  25. if($size = GetImageSize($file)){
  26. $w = $size[0];
  27. $h = $size[1];
  28. //set new size
  29. $nw = $_GET["width"];
  30. $nh = ($nw*$h)/$w;
  31. }
  32. else{
  33. //set new size
  34. $nw = "160";
  35. $nh = "120";
  36. }
  37. //draw the image
  38. $src_img = imagecreatefromjpeg($file);
  39. $dst_img = imagecreatetruecolor($nw,$nh);
  40. imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);//resizing the image
  41. imagejpeg($dst_img,"",100);
  42. imagedestroy($src_img);
  43. imagedestroy($dst_img);
  44. return;
  45. }
  46. break;
  47. case "epub":
  48. header("Content-type: application/epub+zip");
  49. break;
  50. }
  51. $file = $book->getFilePath ($type, true);
  52. header('Content-Disposition: attachement; filename="' . basename ($file) . '"');
  53. header ("X-Accel-Redirect: " . $config['calibre_internal_directory'] . $file);
  54. ?>