Ensure ImageWithImagineInterface.
@param ImageInterface $image
@param ImagePathInterface $path
@return boolean
180519
protected function _thumbnailImage(ImageWithImagineInterface $image, ImagePathInterface $path)
    {
        $this->assertImagine();
        $matches = null;
        if (!preg_match($this->pattern, $path->getPath(), $matches)) {
            return false;
        }
        
        if (is_callable($this->format)) {
            $format = call_user_func($this->format, $matches);
        } else {
            $format = $this->format;
        }
        
        if (false === $format) {
            // force a not found
            throw new ImageNotFoundException(sprintf('Image not found: %s', $path->getPath()));
        }
        
        if (is_null($format)) {
            // passthrough: we want the original image
            return true;
        }
        
        // not very LSP but handy
        if (!$image->getImagine()) {
            $image->setImagine($this->getImagine(), $this->getImagineOptions());
        }
        
        if (true === $format) {
            // we want the original image size but will trigger a save
            $image->deprecateBinaryContent();
            return true;
        }
        
        if (preg_match('/^(\<)?([0-9]+)x([0-9]+)$/', $format, $matches)) {
			$size = new \Imagine\Image\Box($matches[2], $matches[3]);
			$mode = $matches[1] == '<' ? \Imagine\Image\ImageInterface::THUMBNAIL_INSET : \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
		} elseif (preg_match('/^(\<)?([0-9]+)$/', $format, $matches)) {
			$size = new \Imagine\Image\Box($matches[2], $matches[2]);
			$mode = $matches[1] == '<' ? \Imagine\Image\ImageInterface::THUMBNAIL_INSET : \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
		} else {
			throw new ThumbnailRuleException(sprintf('Unsupported rule format: %s', (string)$format), ThumbnailRuleException::UNSUPPORTED_RULE_FORMAT);
		}
        
        /** @var IImage $animated */
        $animated = null;
        $imagine = $image->getImagine();
        if ($this->handleAnimatedGif($image, function (IImage $iimage) use ($imagine, $size, &$animated, $image) {
            $animated = $imagine->create($size);
            $animated->layers()->remove(0);
            $image->setImagineImage($animated);
            // we take first frame conf
            /** @var IImage $iframe */
            $iframe = $iimage->layers()[0];
            $options = [
                'flatten' => false,
                'animated' => true,
                'animated.delay' => $iframe->getImagick()->getImageDelay() * 10,
                'animated.loop' => $iframe->getImagick()->getImageIterations(),
            ];
            $image->setEphemeralImagineOptions($options);
        }, function (IImage $iframe) use ($size, $mode, &$animated) {
            $animated->layers()->add($iframe->thumbnail($size, $mode));
        }, function (IImage $iimage) {
            // nothing
        })) {
            // nothing
            return true;
        }
        $image->setImagineImage($image->getImagineImage()->thumbnail($size, $mode, $this->filter));
		return true;
    }
1073716
protected function handleImageManipulation(ImageInterface $image, array $data): ImageInterface
    {
        $width = $data['width'];
        $height = $data['height'];

        if (isset($data['dimension'])) {
            $width = $height = $data['dimension'];
        }

        return $image->resize(new Box($width, $height), $data['filter']);
    }
560216
public function applyFilter(ImageInterface $image, FilterInterface $filter)
    {
        if ($filter instanceof ImagineAware) {
            if ($this->imagine === null) {
                throw new InvalidArgumentException(sprintf('In order to use %s pass an Imagine\Image\ImagineInterface instance to Transformation constructor', get_class($filter)));
            }
            $filter->setImagine($this->imagine);
        }

        return $filter->apply($image);
    }
1086206
public function addImageFromString($image) {
        if (empty($image)) {
            throw new InvalidArgumentException('Specified image is empty');
        }

        return $this->getCommand('AddImage', array(
            'user' => $this->getUser(),
            'image' => $image,
        ))->execute();
    }
859264
public function applyToImage(Image $image, $x = 0, $y = 0)
    {
        $color = new Color($this->color);
        imageline($image->getCore(), $x, $y, $this->x, $this->y, $color->getInt());

        return true;
    }
1082236
function isImage (path) {
  return new Promise((resolve, reject) => {
    getMimeType(path)
      .then((type) => {
        ;(type.indexOf('image') > -1) ? resolve(true) : resolve(false)
      })
      .catch(err => reject(err))
  })
}
941327
private function _checkImage($img)
    {
        if (!file_exists($img)) {
            $this->_error = 'Image file dom\'t exists! file: ' . $img;
        } elseif (!($type = pathinfo($img, PATHINFO_EXTENSION)) || !self::isSupportedType($type)) {
            $this->_error = "Image type [$type] is not supported.";
        }

        return !$this->hasError();
    }
145730
private function createImageFrom($path)
    {

        $this->gdExtensionCheck();
        switch ($this->getExt()) {
            case 'jpg':
                return imagecreatefromjpeg($path);
                break;
            case 'png':
                return imagecreatefrompng($path);
                break;
            case 'gif':
                return imagecreatefromgif($path);
                break;

            default:
                return imagecreatefrompng($path);
                break;
        }

    }
458287
protected function resizeExact(ImageInterface $image, $width, $height)
    {
        return $image->resize(new Box($width, $height));
    }
1372442
public function selectMainImage(Image $image)
    {
        if (!$this->images->findImageByUUID($image->getMediaObjectId())) {
            throw new \InvalidArgumentException('You can not select a random image to be main, it has to be added to the item.');
        }

        $oldMainImage = $this->images->getMain();

        if (!isset($oldMainImage) || $oldMainImage->getMediaObjectId() !== $image->getMediaObjectId()) {
            $this->apply(
                $this->createMainImageSelectedEvent($image)
            );
        }
    }
1350910
public function save($path)
    {

        switch ( $this->imageType ) {
            case IMAGETYPE_GIF:
                $returnData = imagegif( $this->image, $path );
                break;

            case IMAGETYPE_PNG:
                $returnData = imagepng( $this->image, $path );
                break;

            case IMAGETYPE_JPEG:
                $returnData = imagejpeg( $this->image, $path );
                break;

            case IMAGETYPE_BMP:
                $returnData = imagewbmp( $this->image, $path );
                break;

            // If the image is not one of the previous mimetype
            // We throw an exception
            default:
                throw new Exception( sprintf( 'This MimeType is not supported: %s. Image processed: %s', image_type_to_mime_type( $this->imageType ), $this->originalImagePath ) );
                break;
        }

        // Return this for chaning
        return $this;
    }
519371
final public function make(ImageInterface $image)
    {
        $this->response = new Response(null, 200);
        $this->response->setPublic();

        $lastMod = (new \DateTime)->setTimestamp($modDate = $image->getLastModTime());
        $mod = strtotime($this->request->headers->get('if-modified-since', time()));

        if (($image instanceof CachedImage || !$image->isProcessed()) && $mod === $modDate) {
            $this->setHeadersIfNotProcessed($this->response, $lastMod);
        } else {
            $this->setHeaders($this->response, $image, $lastMod);
        }
    }
1193513
public function dispatchImageOnUploadEvent(ImageInterface $image)
    {
        $imageUploadedEvent = new ImageUploadedEvent($image);

        $this->eventDispatcher->dispatch(
            ElcodiMediaEvents::IMAGE_ONUPLOAD,
            $imageUploadedEvent
        );

        return $this;
    }
504319
public function delete($path=null)
	{
		if (is_null($path)) return;

		$basePath = $this->getImageBasePath();
		$imagePath = $basePath.'/'.$path;

		if (File::exists($imagePath)) {
			File::delete($imagePath);
		}
	}
542131
public function execute($image)
    {
        $mode = $this->argument(0)->type('bool')->value(true);

        if ($mode) {
            $mode = \Imagick::INTERLACE_LINE;
        } else {
            $mode = \Imagick::INTERLACE_NO;
        }

        $image->getCore()->setInterlaceScheme($mode);

        return true;
    }
79420
public function contain(string $path): DriverInterface
    {
        return new Adapters\Contain(
            $this,
            $this->imagePath($path)
        );
    }
19700
protected function render(ImageInterface $image)
    {
        $this->response->make($image);
        $image->close();

        return $this->response->getResponse();
    }