1 | <?php |
||
26 | class PreviewService extends Service { |
||
27 | |||
28 | use Base64Encode; |
||
29 | |||
30 | /** @var Preview */ |
||
31 | private $previewManager; |
||
32 | |||
33 | /** |
||
34 | * Constructor |
||
35 | * |
||
36 | * @param string $appName |
||
37 | * @param Environment $environment |
||
38 | * @param Preview $previewManager |
||
39 | * @param ILogger $logger |
||
40 | */ |
||
41 | 27 | public function __construct( |
|
51 | |||
52 | /** |
||
53 | * Decides if we should download the file instead of generating a preview |
||
54 | * |
||
55 | * @param File $file |
||
56 | * @param bool $animatedPreview |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | 16 | public function isPreviewRequired($file, $animatedPreview) { |
|
72 | |||
73 | /** |
||
74 | * Returns an array containing everything needed by the client to be able to display a preview |
||
75 | * |
||
76 | * * fileid: the file's ID |
||
77 | * * mimetype: the file's media type |
||
78 | * * preview: the preview's content |
||
79 | * |
||
80 | * Example logger |
||
81 | * $this->logger->debug( |
||
82 | * "[PreviewService] Path : {path} / mime: {mimetype} / fileid: {fileid}", |
||
83 | * [ |
||
84 | * 'path' => $preview['data']['path'], |
||
85 | * 'mimetype' => $preview['data']['mimetype'], |
||
86 | * 'fileid' => $preview['fileid'] |
||
87 | * ] |
||
88 | * ); |
||
89 | * |
||
90 | * @todo Get the max size from the settings |
||
91 | * |
||
92 | * @param File $file |
||
93 | * @param int $maxX asked width for the preview |
||
94 | * @param int $maxY asked height for the preview |
||
95 | * @param bool $keepAspect |
||
96 | * @param bool $base64Encode |
||
97 | * |
||
98 | * @return array <string,\OC_Image|string>|false preview data |
||
99 | * @throws InternalServerErrorServiceException |
||
100 | */ |
||
101 | 8 | public function createPreview( |
|
118 | |||
119 | /** |
||
120 | * Makes sure we return previews of the asked dimensions and fix the cache |
||
121 | * if necessary |
||
122 | * |
||
123 | * @param bool $square |
||
124 | * @param bool $base64Encode |
||
125 | * |
||
126 | * @return \OC_Image|string |
||
127 | * @throws InternalServerErrorServiceException |
||
128 | */ |
||
129 | 8 | public function previewValidator($square, $base64Encode) { |
|
143 | |||
144 | /** |
||
145 | * Returns true if the passed mime type is supported |
||
146 | * |
||
147 | * In case of a failure, we just return that the media type is not supported |
||
148 | * |
||
149 | * @param string $mimeType |
||
150 | * |
||
151 | * @return boolean |
||
152 | */ |
||
153 | 12 | private function isMimeSupported($mimeType = '*') { |
|
162 | |||
163 | /** |
||
164 | * Decides if we should download the SVG or generate a preview |
||
165 | * |
||
166 | * SVGs are downloaded if the SVG converter is disabled |
||
167 | * Files of any media type are downloaded if requested by the client |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | 2 | private function isSvgPreviewRequired() { |
|
174 | |||
175 | /** |
||
176 | * Decides if we should download the GIF or generate a preview |
||
177 | * |
||
178 | * GIFs are downloaded if they're animated and we want to show |
||
179 | * animations |
||
180 | * |
||
181 | * @param File $file |
||
182 | * @param bool $animatedPreview |
||
183 | * |
||
184 | * @return bool |
||
185 | */ |
||
186 | 10 | private function isGifPreviewRequired($file, $animatedPreview) { |
|
192 | |||
193 | /** |
||
194 | * Tests if a GIF is animated |
||
195 | * |
||
196 | * An animated gif contains multiple "frames", with each frame having a |
||
197 | * header made up of: |
||
198 | * * a static 4-byte sequence (\x00\x21\xF9\x04) |
||
199 | * * 4 variable bytes |
||
200 | * * a static 2-byte sequence (\x00\x2C) (Photoshop uses \x00\x21) |
||
201 | * |
||
202 | * We read through the file until we reach the end of the file, or we've |
||
203 | * found at least 2 frame headers |
||
204 | * |
||
205 | * @link http://php.net/manual/en/function.imagecreatefromgif.php#104473 |
||
206 | * |
||
207 | * @param File $file |
||
208 | * |
||
209 | * @return bool |
||
210 | * @throws InternalServerErrorServiceException |
||
211 | */ |
||
212 | 10 | private function isGifAnimated($file) { |
|
235 | |||
236 | } |
||
237 |