1
0

StreamImage.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 Carl Schwan <carl@carlschwan.eu>
  4. *
  5. * @author Carl Schwan <carl@carlschwan.eu>
  6. *
  7. * @license AGPL-3.0-or-later
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OC;
  24. use OCP\IStreamImage;
  25. use OCP\IImage;
  26. /**
  27. * Only useful when dealing with transferring streamed previews from an external
  28. * service to an object store.
  29. *
  30. * Only width/height/resource and mimeType are implemented and will give you a
  31. * valid result.
  32. */
  33. class StreamImage implements IStreamImage {
  34. /** @var resource The internal stream */
  35. private $stream;
  36. /** @var null|string */
  37. private $mimeType;
  38. /** @var int */
  39. private $width;
  40. /** @var int */
  41. private $height;
  42. /** @param resource $stream */
  43. public function __construct($stream, string $mimeType, int $width, int $height) {
  44. $this->stream = $stream;
  45. $this->mimeType = $mimeType;
  46. $this->width = $width;
  47. $this->height = $height;
  48. }
  49. /** @inheritDoc */
  50. public function valid(): bool {
  51. return is_resource($this->stream);
  52. }
  53. /** @inheritDoc */
  54. public function mimeType(): ?string {
  55. return $this->mimeType;
  56. }
  57. /** @inheritDoc */
  58. public function width(): int {
  59. return $this->width;
  60. }
  61. /** @inheritDoc */
  62. public function height(): int {
  63. return $this->height;
  64. }
  65. public function widthTopLeft(): int {
  66. throw new \BadMethodCallException('Not implemented');
  67. }
  68. public function heightTopLeft(): int {
  69. throw new \BadMethodCallException('Not implemented');
  70. }
  71. public function show(?string $mimeType = null): bool {
  72. throw new \BadMethodCallException('Not implemented');
  73. }
  74. public function save(?string $filePath = null, ?string $mimeType = null): bool {
  75. throw new \BadMethodCallException('Not implemented');
  76. }
  77. public function resource() {
  78. return $this->stream;
  79. }
  80. public function dataMimeType(): ?string {
  81. return $this->mimeType;
  82. }
  83. public function data(): ?string {
  84. return '';
  85. }
  86. public function getOrientation(): int {
  87. throw new \BadMethodCallException('Not implemented');
  88. }
  89. public function fixOrientation(): bool {
  90. throw new \BadMethodCallException('Not implemented');
  91. }
  92. public function resize(int $maxSize): bool {
  93. throw new \BadMethodCallException('Not implemented');
  94. }
  95. public function preciseResize(int $width, int $height): bool {
  96. throw new \BadMethodCallException('Not implemented');
  97. }
  98. public function centerCrop(int $size = 0): bool {
  99. throw new \BadMethodCallException('Not implemented');
  100. }
  101. public function crop(int $x, int $y, int $w, int $h): bool {
  102. throw new \BadMethodCallException('Not implemented');
  103. }
  104. public function fitIn(int $maxWidth, int $maxHeight): bool {
  105. throw new \BadMethodCallException('Not implemented');
  106. }
  107. public function scaleDownToFit(int $maxWidth, int $maxHeight): bool {
  108. throw new \BadMethodCallException('Not implemented');
  109. }
  110. public function copy(): IImage {
  111. throw new \BadMethodCallException('Not implemented');
  112. }
  113. public function cropCopy(int $x, int $y, int $w, int $h): IImage {
  114. throw new \BadMethodCallException('Not implemented');
  115. }
  116. public function preciseResizeCopy(int $width, int $height): IImage {
  117. throw new \BadMethodCallException('Not implemented');
  118. }
  119. public function resizeCopy(int $maxSize): IImage {
  120. throw new \BadMethodCallException('Not implemented');
  121. }
  122. }