1
0

Image.php 1.8 KB

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