GetImageSize.php in File metadata manager 8
File
src/Plugin/FileMetadata/GetImageSize.php
View source
<?php
namespace Drupal\file_mdm\Plugin\FileMetadata;
use Drupal\file_mdm\FileMetadataException;
class GetImageSize extends FileMetadataPluginBase {
public function getSupportedKeys($options = NULL) {
return [
0,
1,
2,
3,
'mime',
'channels',
'bits',
];
}
protected function doGetMetadataFromFile() {
if ($data = @getimagesize($this
->getLocalTempPath())) {
return $data;
}
else {
return NULL;
}
}
protected function validateKey($key, $method) {
if (!is_int($key) && !is_string($key)) {
throw new FileMetadataException("Invalid metadata key specified", $this
->getPluginId(), $method);
}
if (!in_array($key, $this
->getSupportedKeys(), TRUE)) {
throw new FileMetadataException("Invalid metadata key '{$key}' specified", $this
->getPluginId(), $method);
}
return TRUE;
}
protected function doGetMetadata($key = NULL) {
if ($key === NULL) {
return $this->metadata;
}
else {
$this
->validateKey($key, __FUNCTION__);
return isset($this->metadata[$key]) ? $this->metadata[$key] : NULL;
}
}
protected function doSetMetadata($key, $value) {
$this
->validateKey($key, __FUNCTION__);
$this->metadata[$key] = $value;
return TRUE;
}
protected function doRemoveMetadata($key) {
$this
->validateKey($key, __FUNCTION__);
if (isset($this->metadata[$key])) {
unset($this->metadata[$key]);
}
return TRUE;
}
}