Image.php 892 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Preview;
  8. use OCP\Files\File;
  9. use OCP\IImage;
  10. abstract class Image extends ProviderV2 {
  11. /**
  12. * {@inheritDoc}
  13. */
  14. public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
  15. $maxSizeForImages = \OC::$server->getConfig()->getSystemValueInt('preview_max_filesize_image', 50);
  16. $size = $file->getSize();
  17. if ($maxSizeForImages !== -1 && $size > ($maxSizeForImages * 1024 * 1024)) {
  18. return null;
  19. }
  20. $image = new \OCP\Image();
  21. $fileName = $this->getLocalFile($file);
  22. $image->loadFromFile($fileName);
  23. $image->fixOrientation();
  24. $this->cleanTmpFiles();
  25. if ($image->valid()) {
  26. $image->scaleDownToFit($maxX, $maxY);
  27. return $image;
  28. }
  29. return null;
  30. }
  31. }