Improved error messages in ImageConverter

This commit is contained in:
Marcin Kurczewski 2014-10-25 18:49:03 +02:00
parent 766fc05075
commit 8bae666275

View file

@ -25,8 +25,7 @@ class ImageConverter
try try
{ {
file_put_contents($tmpSourcePath, $source); file_put_contents($tmpSourcePath, $source);
if (!$this->convert($tmpSourcePath, $tmpTargetPath)) $this->convert($tmpSourcePath, $tmpTargetPath);
throw new \Exception('Error while converting supplied file to image');
$tmpSource = file_get_contents($tmpTargetPath); $tmpSource = file_get_contents($tmpTargetPath);
return $this->imageManipulator->loadFromBuffer($tmpSource); return $this->imageManipulator->loadFromBuffer($tmpSource);
@ -43,18 +42,16 @@ class ImageConverter
$mime = MimeHelper::getMimeTypeFromFile($sourcePath); $mime = MimeHelper::getMimeTypeFromFile($sourcePath);
if (MimeHelper::isImage($mime)) if (MimeHelper::isImage($mime))
{
copy($sourcePath, $targetPath); copy($sourcePath, $targetPath);
return true;
}
if (MimeHelper::isFlash($mime)) elseif (MimeHelper::isFlash($mime))
return $this->convertFromFlash($sourcePath, $targetPath); $this->convertFromFlash($sourcePath, $targetPath);
if (MimeHelper::isVideo($mime)) elseif (MimeHelper::isVideo($mime))
return $this->convertFromVideo($sourcePath, $targetPath); $this->convertFromVideo($sourcePath, $targetPath);
return false; else
throw new \Exception('Error while converting file to image - unrecognized MIME: ' . $mime);
} }
private function convertFromFlash($sourcePath, $targetPath) private function convertFromFlash($sourcePath, $targetPath)
@ -86,9 +83,7 @@ class ImageConverter
} }
if (!file_exists($targetPath)) if (!file_exists($targetPath))
return false; throw new \Exception('Error while converting Flash file to image');
return true;
} }
private function convertFromVideo($sourcePath, $targetPath) private function convertFromVideo($sourcePath, $targetPath)
@ -116,9 +111,7 @@ class ImageConverter
} }
if (!file_exists($targetPath)) if (!file_exists($targetPath))
return false; throw new \Exception('Error while converting video file to image');
return true;
} }
private function deleteIfExists($path) private function deleteIfExists($path)