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.

64 lines
1.8 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.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 Roeland Jago Douma <roeland@famdouma.nl>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. * @author Thomas Tanghus <thomas@tanghus.net>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OC\Preview;
  30. use OCP\Files\File;
  31. use OCP\IImage;
  32. abstract class Image extends ProviderV2 {
  33. /**
  34. * {@inheritDoc}
  35. */
  36. public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
  37. $maxSizeForImages = \OC::$server->getConfig()->getSystemValue('preview_max_filesize_image', 50);
  38. $size = $file->getSize();
  39. if ($maxSizeForImages !== -1 && $size > ($maxSizeForImages * 1024 * 1024)) {
  40. return null;
  41. }
  42. $image = new \OC_Image();
  43. $fileName = $this->getLocalFile($file);
  44. $image->loadFromFile($fileName);
  45. $image->fixOrientation();
  46. $this->cleanTmpFiles();
  47. if ($image->valid()) {
  48. $image->scaleDownToFit($maxX, $maxY);
  49. return $image;
  50. }
  51. return null;
  52. }
  53. }