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;
    }