Exemple #1
0
 /**
  * Returns generated name for a image
  *
  * @param \Imager\ImageInfo $image
  * @return string
  */
 public static function createName(ImageInfo $image)
 {
     $source = $image->getSource() ?: $image;
     $id = $image->getParameter('id');
     if (!isset($id)) {
         $name = md5($source->getPathname());
     } else {
         $name = Strings::before($id, '.', -1);
     }
     // dimensions of image only for thumbnail (has source)
     $width = $image->getParameter('width');
     $height = $image->getParameter('height');
     $quality = $image->getParameter('quality');
     $dimensionName = self::createDimensionName($width, $height, $quality);
     if ($source->getExtension() !== '') {
         $ext = '.' . $source->getExtension();
     } else {
         $extensions = [IMAGETYPE_GIF => '.gif', IMAGETYPE_JPEG => '.jpg', IMAGETYPE_PNG => '.png', IMAGETYPE_BMP => '.bmp'];
         if (!array_key_exists($source->getType(), $extensions)) {
             $msg = sprintf('Image "%s" is unsupported type.', $source->getFilename());
             throw new InvalidStateException($msg);
         }
         $ext = $extensions[$source->getType()];
     }
     $fileName = $name . $dimensionName . $ext;
     return $fileName;
 }