Image.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Georg Ehrke <georg@owncloud.com>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author josh4trunks <joshruehlig@gmail.com>
  8. * @author Olivier Paroz <github@oparoz.com>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. * @author Thomas Tanghus <thomas@tanghus.net>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OC\Preview;
  29. abstract class Image extends Provider {
  30. /**
  31. * {@inheritDoc}
  32. */
  33. public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
  34. //get fileinfo
  35. $fileInfo = $fileview->getFileInfo($path);
  36. if (!$fileInfo) {
  37. return false;
  38. }
  39. $maxSizeForImages = \OC::$server->getConfig()->getSystemValue('preview_max_filesize_image', 50);
  40. $size = $fileInfo->getSize();
  41. if ($maxSizeForImages !== -1 && $size > ($maxSizeForImages * 1024 * 1024)) {
  42. return false;
  43. }
  44. $image = new \OC_Image();
  45. $useTempFile = $fileInfo->isEncrypted() || !$fileInfo->getStorage()->isLocal();
  46. if ($useTempFile) {
  47. $fileName = $fileview->toTmpFile($path);
  48. } else {
  49. $fileName = $fileview->getLocalFile($path);
  50. }
  51. $image->loadFromFile($fileName);
  52. $image->fixOrientation();
  53. if ($useTempFile) {
  54. unlink($fileName);
  55. }
  56. if ($image->valid()) {
  57. $image->scaleDownToFit($maxX, $maxY);
  58. return $image;
  59. }
  60. return false;
  61. }
  62. }