blob: 892671556b36806c2e5fb802d71bcf43a667c92c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<?php
namespace OC\Metadata\Provider;
use OC\Metadata\FileMetadata;
use OC\Metadata\IMetadataProvider;
use OCP\Files\File;
class ExifProvider implements IMetadataProvider {
public static function groupsProvided(): array {
return ['size'];
}
public static function isAvailable(): bool {
return extension_loaded('exif');
}
public function execute(File $file): array {
$fileDescriptor = $file->fopen('rb');
$data = exif_read_data($fileDescriptor, 'COMPUTED', true);
$size = new FileMetadata();
$size->setGroupName('size');
$size->setId($file->getId());
$size->setMetadata([]);
if (!$data) {
$sizeResult = getimagesizefromstring($file->getContent());
if ($sizeResult !== false) {
$size->setMetadata([
'width' => $sizeResult[0],
'height' => $sizeResult[1],
]);
}
return [
'size' => $size,
];
}
if (array_key_exists('COMPUTED', $data)
&& array_key_exists('Width', $data['COMPUTED'])
&& array_key_exists('Height', $data['COMPUTED'])
) {
$size->setMetadata([
'width' => $data['COMPUTED']['Width'],
'height' => $data['COMPUTED']['Height'],
]);
}
return [
'size' => $size,
];
}
public static function getMimetypesSupported(): string {
return '/image\/.*/';
}
}
|