1 | <?php |
||
28 | class Preview { |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $dataDir; |
||
34 | /** |
||
35 | * @var mixed |
||
36 | */ |
||
37 | private $previewManager; |
||
38 | /** |
||
39 | * @var ILogger |
||
40 | */ |
||
41 | private $logger; |
||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $userId; |
||
46 | /** |
||
47 | * @var \OC\Preview |
||
48 | */ |
||
49 | private $preview; |
||
50 | /** |
||
51 | * @var File |
||
52 | */ |
||
53 | private $file; |
||
54 | /** |
||
55 | * @var int[] |
||
56 | */ |
||
57 | private $dims; |
||
58 | |||
59 | /** |
||
60 | * Constructor |
||
61 | * |
||
62 | * @param IConfig $config |
||
63 | * @param IPreview $previewManager |
||
64 | * @param ILogger $logger |
||
65 | */ |
||
66 | 43 | public function __construct( |
|
75 | |||
76 | /** |
||
77 | * Returns true if the passed mime type is supported |
||
78 | * |
||
79 | * @param string $mimeType |
||
80 | * |
||
81 | * @return boolean |
||
82 | */ |
||
83 | 16 | public function isMimeSupported($mimeType = '*') { |
|
86 | |||
87 | /** |
||
88 | * Initialises the view which will be used to access files and generate previews |
||
89 | * |
||
90 | * @fixme Private API, but can't use the PreviewManager yet as it's incomplete |
||
91 | * |
||
92 | * @param string $userId |
||
93 | * @param File $file |
||
94 | * @param string $imagePathFromFolder |
||
95 | */ |
||
96 | 7 | public function setupView($userId, $file, $imagePathFromFolder) { |
|
102 | |||
103 | /** |
||
104 | * Returns a preview based on OC's preview class and our custom methods |
||
105 | * |
||
106 | * We check that the preview returned by the Preview class can be used by |
||
107 | * the browser. If not, we send "false" to the controller |
||
108 | * |
||
109 | * @fixme setKeepAspect is missing from public interface. |
||
110 | * https://github.com/owncloud/core/issues/12772 |
||
111 | * |
||
112 | * @param int $maxWidth |
||
113 | * @param int $maxHeight |
||
114 | * @param bool $keepAspect |
||
115 | * |
||
116 | * @return array<string,string|\OC_Image>|false |
||
117 | */ |
||
118 | 7 | public function preparePreview($maxWidth, $maxHeight, $keepAspect) { |
|
134 | |||
135 | /** |
||
136 | * Makes sure we return previews of the asked dimensions and fix the cache |
||
137 | * if necessary |
||
138 | * |
||
139 | * The Preview class sometimes return previews which are either wider or |
||
140 | * smaller than the asked dimensions. This happens when one of the original |
||
141 | * dimension is smaller than what is asked for |
||
142 | * |
||
143 | * For square previews, we also need to make sure the entire surface is filled in order to make |
||
144 | * it easier to work with when building albums |
||
145 | * |
||
146 | * @param bool $square |
||
147 | * |
||
148 | * @return \OC_Image |
||
149 | */ |
||
150 | 12 | public function previewValidator($square) { |
|
164 | |||
165 | /** |
||
166 | * Asks core for a preview based on our criteria |
||
167 | * |
||
168 | * @todo Need to read scaling setting from settings |
||
169 | * |
||
170 | * @param bool $keepAspect |
||
171 | * |
||
172 | * @return \OC_Image |
||
173 | */ |
||
174 | 8 | private function getPreviewFromCore($keepAspect) { |
|
188 | |||
189 | /** |
||
190 | * Makes a preview fit in the asked dimension and, if required, fills the empty space |
||
191 | * |
||
192 | * @param \OCP\IImage $previewData |
||
193 | * @param int $previewWidth |
||
194 | * @param int $previewHeight |
||
195 | * @param int $maxWidth |
||
196 | * @param int $maxHeight |
||
197 | * @param bool $square |
||
198 | * |
||
199 | * @return \OC_Image |
||
200 | */ |
||
201 | 7 | private function fixPreview( |
|
214 | |||
215 | /** |
||
216 | * Makes a preview fit in the asked dimension and, if required, fills the empty space |
||
217 | * |
||
218 | * @param \OCP\IImage $previewData |
||
219 | * @param int $previewWidth |
||
220 | * @param int $previewHeight |
||
221 | * @param int $maxWidth |
||
222 | * @param int $maxHeight |
||
223 | * @param bool $fill |
||
224 | * |
||
225 | * @return resource |
||
226 | */ |
||
227 | 7 | private function resize( |
|
246 | |||
247 | /** |
||
248 | * Mixes a transparent background with a resized foreground preview |
||
249 | * |
||
250 | * @param \OCP\IImage $previewData |
||
251 | * @param int $previewWidth |
||
252 | * @param int $previewHeight |
||
253 | * @param int $newWidth |
||
254 | * @param int $newHeight |
||
255 | * @param int $maxWidth |
||
256 | * @param int $maxHeight |
||
257 | * @param int $newX |
||
258 | * @param int $newY |
||
259 | * |
||
260 | * @return resource |
||
261 | */ |
||
262 | 7 | private function processPreview( |
|
282 | |||
283 | /** |
||
284 | * Calculates the new dimensions so that it fits in the dimensions requested by the client |
||
285 | * |
||
286 | * @link https://stackoverflow.com/questions/3050952/resize-an-image-and-fill-gaps-of-proportions-with-a-color |
||
287 | * |
||
288 | * @param int $previewWidth |
||
289 | * @param int $previewHeight |
||
290 | * @param int $maxWidth |
||
291 | * @param int $maxHeight |
||
292 | * |
||
293 | * @return array<int,double> |
||
294 | */ |
||
295 | 7 | private function calculateNewDimensions($previewWidth, $previewHeight, $maxWidth, $maxHeight) { |
|
310 | |||
311 | /** |
||
312 | * Fixes the preview cache by replacing the broken thumbnail with ours |
||
313 | * |
||
314 | * WARNING: Will break if the thumbnail folder ever moves or if encryption is turned on for |
||
315 | * thumbnails |
||
316 | * |
||
317 | * @param resource $fixedPreview |
||
318 | * |
||
319 | * @return \OCP\IImage |
||
320 | */ |
||
321 | 7 | private function fixPreviewCache($fixedPreview) { |
|
339 | |||
340 | } |
||
341 |