public function createImage(File $file)
    {
        $fileMime = $file->getMimeType();

        if ('application/octet-stream' === $fileMime) {
            $imageSizeData = getimagesize($file->getPathname());
            $fileMime = $imageSizeData['mime'];
        }

        if (strpos($fileMime, 'image/') !== 0) {
            throw new InvalidImageException();
        }

        $extension = $file->getExtension();

        if (!$extension && $file instanceof UploadedFile) {
            $extension = $file->getClientOriginalExtension();
        }

        /**
         * @var ImageInterface $image
         */
        $image = $this->imageFactory->create();

        if (!isset($imageSizeData)) {
            $imageSizeData = getimagesize($file->getPathname());
        }
        $name = $file->getFilename();
        $image
            ->setWidth($imageSizeData[0])
            ->setHeight($imageSizeData[1])
            ->setContentType($fileMime)
            ->setSize($file->getSize())
            ->setExtension($extension)
            ->setName($name);

        return $image;
    }
public function createImage(File $file)
    {
        $fileMime = $file->getMimeType();

        if ('application/octet-stream' === $fileMime) {
            $imageSizeData = getimagesize($file->getPathname());
            $fileMime = $imageSizeData['mime'];
        }

        if (strpos($fileMime, 'image/') !== 0) {
            throw new InvalidImageException();
        }

        $extension = $file->getExtension();

        if (!$extension && $file instanceof UploadedFile) {
            $extension = $file->getClientOriginalExtension();
        }

        /**
         * @var ImageInterface $image
         */
        $image = $this->imageFactory->create();

        if (!isset($imageSizeData)) {
            $imageSizeData = getimagesize($file->getPathname());
        }
        $name = $file->getFilename();
        $image
            ->setWidth($imageSizeData[0])
            ->setHeight($imageSizeData[1])
            ->setContentType($fileMime)
            ->setSize($file->getSize())
            ->setExtension($extension)
            ->setName($name);

        return $image;
    }
public function createImage ( File $ file ) { $ fileMime = $ file -> getMimeType ( ) ; if ( 'application/octet-stream' === $ fileMime ) { $ imageSizeData = getimagesize ( $ file -> getPathname ( ) ) ; $ fileMime = $ imageSizeData [ 'mime' ] ; } if ( strpos ( $ fileMime , 'image/' ) !== 0 ) { throw new InvalidImageException ( ) ; } $ extension = $ file -> getExtension ( ) ; if ( ! $ extension && $ file instanceof UploadedFile ) { $ extension = $ file -> getClientOriginalExtension ( ) ; } /**
         * @var ImageInterface $image
         */ $ image = $ this -> imageFactory -> create ( ) ; if ( ! isset ( $ imageSizeData ) ) { $ imageSizeData = getimagesize ( $ file -> getPathname ( ) ) ; } $ name = $ file -> getFilename ( ) ; $ image -> setWidth ( $ imageSizeData [ 0 ] ) -> setHeight ( $ imageSizeData [ 1 ] ) -> setContentType ( $ fileMime ) -> setSize ( $ file -> getSize ( ) ) -> setExtension ( $ extension ) -> setName ( $ name ) ; return $ image ; }
Given a single File, assuming is an image, create a new
Image object containing all needed information.

This method also persists and flush created entity

@param File $file File where to get the image

@return ImageInterface Image created

@throws InvalidImageException File is not an image
Given a single File assuming is an image create a new Image object containing all needed information .