blob: 91c858f6794877eea3fbe1885f98a5ba1a577087 (
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
|
<?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, 'ANY_TAG', true);
$size = new FileMetadata();
$size->setGroupName('size');
$size->setId($file->getId());
$size->setMetadata([]);
if (!$data) {
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\/.*/';
}
}
|