supportedMimeType() public static method

Check if a mime type is supported by Imbo
public static supportedMimeType ( string $mime ) : boolean
$mime string The mime type to check. For instance "image/png"
return boolean
Beispiel #1
0
 /**
  * Prepare an image
  *
  * This method should prepare an image object from php://input. The method must also figure out
  * the width, height, mime type and extension of the image.
  *
  * @param EventInterface $event The current event
  * @throws ImageException
  */
 public function prepareImage(EventInterface $event)
 {
     $request = $event->getRequest();
     // Fetch image data from input
     $imageBlob = $request->getContent();
     if (empty($imageBlob)) {
         $e = new ImageException('No image attached', 400);
         $e->setImboErrorCode(Exception::IMAGE_NO_IMAGE_ATTACHED);
         throw $e;
     }
     // Open the image with imagick to fetch the mime type
     $imagick = new Imagick();
     try {
         $imagick->readImageBlob($imageBlob);
         $mime = $imagick->getImageMimeType();
         $size = $imagick->getImageGeometry();
     } catch (ImagickException $e) {
         $e = new ImageException('Invalid image', 415);
         $e->setImboErrorCode(Exception::IMAGE_INVALID_IMAGE);
         throw $e;
     }
     if (!Image::supportedMimeType($mime)) {
         $e = new ImageException('Unsupported image type: ' . $mime, 415);
         $e->setImboErrorCode(Exception::IMAGE_UNSUPPORTED_MIMETYPE);
         throw $e;
     }
     // Store relevant information in the image instance and attach it to the request
     $image = new Image();
     $image->setMimeType($mime)->setExtension(Image::getFileExtension($mime))->setBlob($imageBlob)->setWidth($size['width'])->setHeight($size['height'])->setOriginalChecksum(md5($imageBlob));
     $request->setImage($image);
 }
Beispiel #2
0
 /**
  * @covers Imbo\Model\Image::supportedMimeType
  * @dataProvider getSupportedMimeTypes
  */
 public function testCanInformAboutSupportedMimeType($type, $result)
 {
     $this->assertSame($result, Image::supportedMimeType($type));
 }