Skip to content

Commit 6b9ab07

Browse files
authored
Cleanup of getMimeType() (#1534)
- Removed unneeded call to image_type_to_mime_type() because the mime type is already determined by getimagesize() - Removed returning $this->_fileType. This is NOT the mime type and not in use anywhere, so safe to remove. - More readable code - New exception if image is unreadable
1 parent bd20713 commit 6b9ab07

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/Varien/Image/Adapter/Abstract.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,18 @@ abstract public function checkDependencies();
154154

155155
public function getMimeType()
156156
{
157-
if( $this->_fileType ) {
158-
return $this->_fileType;
159-
} else {
160-
list($this->_imageSrcWidth, $this->_imageSrcHeight, $this->_fileType, ) = getimagesize($this->_fileName);
161-
$this->_fileMimeType = image_type_to_mime_type($this->_fileType);
157+
if($this->_fileMimeType){
162158
return $this->_fileMimeType;
163159
}
160+
$imageInfo = @getimagesize($this->_fileName);
161+
if($imageInfo === false){
162+
throw new RuntimeException('Failed to read image at ' . $this->_fileName);
163+
}
164+
$this->_imageSrcWidth = $imageInfo[0];
165+
$this->_imageSrcHeight = $imageInfo[1];
166+
$this->_fileType = $imageInfo[2];
167+
$this->_fileMimeType = $imageInfo['mime'];
168+
return $this->_fileMimeType;
164169
}
165170

166171
/**

0 commit comments

Comments
 (0)