Skip to content
Snippets Groups Projects
Commit 2176bfda authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2217783 by mondrake: Remove $extension and $mimeType from Image, use...

Issue #2217783 by mondrake: Remove $extension and $mimeType from Image, use image_type_to_xxx function in the getters instead.
parent c1cf341b
No related branches found
No related tags found
No related merge requests found
......@@ -47,13 +47,6 @@ class Image implements ImageInterface {
*/
protected $width = 0;
/**
* Commonly used file extension for the image.
*
* @var string
*/
protected $extension = '';
/**
* Image type represented by a PHP IMAGETYPE_* constant (e.g. IMAGETYPE_JPEG).
*
......@@ -61,13 +54,6 @@ class Image implements ImageInterface {
*/
protected $type;
/**
* MIME type (e.g. 'image/jpeg', 'image/gif', 'image/png').
*
* @var string
*/
protected $mimeType = '';
/**
* File size in bytes.
*
......@@ -110,14 +96,6 @@ public function isExisting() {
return $this->processed;
}
/**
* {@inheritdoc}
*/
public function getExtension() {
$this->processInfo();
return $this->extension;
}
/**
* {@inheritdoc}
*/
......@@ -171,7 +149,7 @@ public function getType() {
*/
public function getMimeType() {
$this->processInfo();
return $this->mimeType;
return $this->type ? image_type_to_mime_type($this->type) : '';
}
/**
......@@ -250,15 +228,7 @@ protected function processInfo() {
$this->height = $details['height'];
$this->width = $details['width'];
$this->type = $details['type'];
$this->mimeType = $details['mime_type'];
$this->fileSize = filesize($destination);
$this->extension = pathinfo($destination, PATHINFO_EXTENSION);
// It may be a temporary file, without extension, or an image created from
// an image resource. Fallback to default extension for this image type.
if (empty($this->extension)) {
$this->extension = image_type_to_extension($this->type, FALSE);
}
$this->processed = TRUE;
}
......
......@@ -28,14 +28,6 @@ public function isSupported();
*/
public function isExisting();
/**
* Returns the extension of the image file.
*
* @return string
* The extension of the file, or an empty string if the file is invalid.
*/
public function getExtension();
/**
* Returns the height of the image file.
*
......@@ -93,7 +85,8 @@ public function getType();
* Returns the MIME type of the image file.
*
* @return string
* The MIME type of the file, or an empty string if the file is invalid.
* The MIME type of the image file, or an empty string if the image is
* invalid.
*/
public function getMimeType();
......
......@@ -199,7 +199,6 @@ public function scaleAndCrop(ImageInterface $image, $width, $height);
* - "width": Width, in pixels.
* - "height": Height, in pixels.
* - "type": Image type represented as an IMAGETYPE_* constant.
* - "mime_type": MIME type (e.g. 'image/jpeg', 'image/gif', 'image/png').
*
* @see \Drupal\Core\Image\ImageInterface::processInfo()
*/
......
......@@ -166,7 +166,7 @@ public static function process($element, &$form_state, $form) {
}
else {
$image = \Drupal::service('image.factory')->get($file->getFileUri());
if ($image->getExtension()) {
if ($image->isExisting()) {
$variables['width'] = $image->getWidth();
$variables['height'] = $image->getHeight();
}
......
......@@ -309,7 +309,6 @@ public function getInfo(ImageInterface $image) {
'width' => $data[0],
'height' => $data[1],
'type' => $data[2],
'mime_type' => $data['mime'],
);
}
......
......@@ -253,7 +253,7 @@ function testManipulations() {
$directory = $this->public_files_directory .'/imagetest';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
$image->save($directory . '/' . $op . '.' . $image->getExtension());
$image->save($directory . '/' . $op . image_type_to_extension($image->getType()));
$this->assertTrue($correct_dimensions_real, String::format('Image %file after %action action has proper dimensions.', array('%file' => $file, '%action' => $op)));
$this->assertTrue($correct_dimensions_object, String::format('Image %file object after %action action is reporting the proper height and width values.', array('%file' => $file, '%action' => $op)));
......
......@@ -59,7 +59,6 @@ public function getInfo(ImageInterface $image) {
'width' => $data[0],
'height' => $data[1],
'type' => $data[2],
'mime_type' => $data['mime'],
);
}
......
......@@ -77,13 +77,6 @@ protected function getToolkitMock(array $stubs = array()) {
->getMock();
}
/**
* Tests \Drupal\Core\Image\Image::getExtension().
*/
public function testGetExtension() {
$this->assertEquals($this->image->getExtension(), 'png');
}
/**
* Tests \Drupal\Core\Image\Image::getHeight().
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment