1
0

StreamImage.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC;
  8. use OCP\IImage;
  9. use OCP\IStreamImage;
  10. /**
  11. * Only useful when dealing with transferring streamed previews from an external
  12. * service to an object store.
  13. *
  14. * Only width/height/resource and mimeType are implemented and will give you a
  15. * valid result.
  16. */
  17. class StreamImage implements IStreamImage {
  18. /** @var resource The internal stream */
  19. private $stream;
  20. /** @var null|string */
  21. private $mimeType;
  22. /** @var int */
  23. private $width;
  24. /** @var int */
  25. private $height;
  26. /** @param resource $stream */
  27. public function __construct($stream, string $mimeType, int $width, int $height) {
  28. $this->stream = $stream;
  29. $this->mimeType = $mimeType;
  30. $this->width = $width;
  31. $this->height = $height;
  32. }
  33. /** @inheritDoc */
  34. public function valid(): bool {
  35. return is_resource($this->stream);
  36. }
  37. /** @inheritDoc */
  38. public function mimeType(): ?string {
  39. return $this->mimeType;
  40. }
  41. /** @inheritDoc */
  42. public function width(): int {
  43. return $this->width;
  44. }
  45. /** @inheritDoc */
  46. public function height(): int {
  47. return $this->height;
  48. }
  49. public function widthTopLeft(): int {
  50. throw new \BadMethodCallException('Not implemented');
  51. }
  52. public function heightTopLeft(): int {
  53. throw new \BadMethodCallException('Not implemented');
  54. }
  55. public function show(?string $mimeType = null): bool {
  56. throw new \BadMethodCallException('Not implemented');
  57. }
  58. public function save(?string $filePath = null, ?string $mimeType = null): bool {
  59. throw new \BadMethodCallException('Not implemented');
  60. }
  61. public function resource() {
  62. return $this->stream;
  63. }
  64. public function dataMimeType(): ?string {
  65. return $this->mimeType;
  66. }
  67. public function data(): ?string {
  68. return '';
  69. }
  70. public function getOrientation(): int {
  71. throw new \BadMethodCallException('Not implemented');
  72. }
  73. public function fixOrientation(): bool {
  74. throw new \BadMethodCallException('Not implemented');
  75. }
  76. public function resize(int $maxSize): bool {
  77. throw new \BadMethodCallException('Not implemented');
  78. }
  79. public function preciseResize(int $width, int $height): bool {
  80. throw new \BadMethodCallException('Not implemented');
  81. }
  82. public function centerCrop(int $size = 0): bool {
  83. throw new \BadMethodCallException('Not implemented');
  84. }
  85. public function crop(int $x, int $y, int $w, int $h): bool {
  86. throw new \BadMethodCallException('Not implemented');
  87. }
  88. public function fitIn(int $maxWidth, int $maxHeight): bool {
  89. throw new \BadMethodCallException('Not implemented');
  90. }
  91. public function scaleDownToFit(int $maxWidth, int $maxHeight): bool {
  92. throw new \BadMethodCallException('Not implemented');
  93. }
  94. public function copy(): IImage {
  95. throw new \BadMethodCallException('Not implemented');
  96. }
  97. public function cropCopy(int $x, int $y, int $w, int $h): IImage {
  98. throw new \BadMethodCallException('Not implemented');
  99. }
  100. public function preciseResizeCopy(int $width, int $height): IImage {
  101. throw new \BadMethodCallException('Not implemented');
  102. }
  103. public function resizeCopy(int $maxSize): IImage {
  104. throw new \BadMethodCallException('Not implemented');
  105. }
  106. public function loadFromData(string $str): \GdImage|false {
  107. throw new \BadMethodCallException('Not implemented');
  108. }
  109. public function readExif(string $data): void {
  110. throw new \BadMethodCallException('Not implemented');
  111. }
  112. }