Ensure certain image storages und formats

@param string       $image
@param array|int    $formats
@param array|string $storages
@return string
499378
public function ensure($image, $formats, $storages)
    {
        $storage = $this->getImageStorage($image);
        $format = $this->getImageFormat($image);

        $storages = is_string($storages) ? array($storages) : $storages;
        $formats = is_int($formats) ? array($formats) : $formats;
        if (in_array($format, $formats)) {
            if (in_array($storage, $storages)) {
                return $image;
            } else {
                $file = $this->getFileOptionForSaving($storages);
                $image = $this->loadToString($image);
                return $this->saveFromString($image, array('file' => $file));
            }
        } else {
            $file = $this->getFileOptionForSaving($storages);
            $resource = $this->load($image);
            return $this->save($resource, array('file' => $file, 'format' => $formats[0]));
        }
    }
567835
public function srcset($images, $descriptor = 'w'): string
    {
        $r = '';
        $generated = [];

        if (!\is_array($images)) {
            return '';
        }

        foreach ($images as $image) {
            switch ($descriptor) {
                case 'w':
                    if (!isset($generated[$image->getWidth()])) {
                        $r .= $image->getUrl().' '.$image->getWidth().'w, ';
                        $generated[$image->getWidth()] = true;
                    }
                    break;
                case 'h':
                    if (!isset($generated[$image->getHeight()])) {
                        $r .= $image->getUrl().' '.$image->getHeight().'h, ';
                        $generated[$image->getHeight()] = true;
                    }
                    break;
                case 'w+h':
                    $key = $image->getWidth().'x'.$image->getHeight();
                    if (!isset($generated[$key])) {
                        $r .= $image->getUrl().' '.$image->getWidth().'w '.$image->getHeight().'h, ';
                        $generated[$image->getWidth().'x'.$image->getHeight()] = true;
                    }
                    break;
            }
        }

        return $r !== '' ? substr($r, 0, -2) : '';
    }
664444
private function addRequestFormats(Request $request, array $formats): void
    {
        foreach ($formats as $format => $mimeTypes) {
            $request->setFormat($format, (array) $mimeTypes);
        }
    }
513268
public function format($format)
    {
        if (!$this->image) {
            $this->image();
        }

        $this->format = $format;

        return $this;
    }
1294252
public function prepare($image)
    {
        if (request()->has(static::FILE_DELETE_FLAG)) {
            return $this->destroy();
        }

        $this->name = $this->getStoreName($image);

        $this->callInterventionMethods($image->getRealPath());

        return $this->uploadAndDeleteOriginal($image);
    }
879233
protected function normalizeFormat($format)
    {
        $format = strtolower(trim((string) $format));
        if ($format === 'jpg') {
            $format = static::FORMAT_JPEG;
        }

        return $format;
    }
741290
public function imageInspect($image)
    {
        return $this->browser->get(
            $this->uri->expand(
                '/images/{image}/json',
                array(
                    'image' => $image
                )
            )
        )->then(array($this->parser, 'expectJson'));
    }
1112872
public function resizePortraitImage($image)
    {
        $images = array();
        $original_width = imagesx($image);
        $originl_height = imagesy($image);

        foreach ($this->_sizes as $name => $size) {
            if (!is_int($size)) {
                list($width, $height) = AnHelperImage::parseSize($size);
                if ($original_width < $width) {
                    $size = array($original_width, $originl_height);
                } else {
                    $size = array($width, 'auto');
                }
            }

            $data = AnHelperImage::resize($image, $size);
            $width = imagesx($data);
            $height = imagesy($data);
            $images[$name] = array('size' => $width.'x'.$height,'data' => $data);
        }

        if ($this->_keep_original) {
            $images['original'] = array('size' => $original_width.'x'.$originl_height, 'data' => $image);
        }

        return $images;
    }
1098517
public function transform($image, $transforms)
    {
        /** @var ConfigModel $settings */
        $config = ImagerService::getConfig();

        $sourceModel = new LocalSourceImageModel($image);

        $transformedImages = [];

        foreach ($transforms as $transform) {
            $transformedImages[] = $this->getTransformedImage($sourceModel, $transform);
        }

        $taskCreated = false;

        // Loop over transformed images and do post optimizations and upload to external storage 
        foreach ($transformedImages as $transformedImage) {
            /** @var CraftTransformedImageModel $transformedImage */
            if ($transformedImage->isNew) {
                $isFinalVersion = $this->optimize($transformedImage);
                $this->store($transformedImage, $isFinalVersion);

                if (!$isFinalVersion) {
                    $taskCreated = true;
                }
            }
        }

        // If ajax request, trigger jobs immediately
        if (!Craft::$app->getRequest()->isConsoleRequest && $taskCreated && $config->runJobsImmediatelyOnAjaxRequests && Craft::$app->getRequest()->getIsAjax()) {
            $this->triggerQueueNow();
        }

        return $transformedImages;
    }
778485
public function setFormattedImages(FormattedImageCollection $formattedImages)
    {
        return parent::setFormattedImages($formattedImages->map(function (FormattedImage $formattedImage) {
            return $formattedImage->setImage($this);
        }));
    }
716483
public function form($image, $options=array()){

        $data = array();
        
        $data['image'] = base64_encode($image);

        $data = array_merge($data, $options);

        return $this->request($this->formUrl, $data);
    }
996305
public function imagePath($image)
    {
        if (!$image) {
            return '';
        }

        $parts = explode(';', $image);
        $fileId = $parts[0];

        // deliver original file
        $src = $this->router->generate('frontendmedia_inline', ['fileId' => $fileId], UrlGeneratorInterface::ABSOLUTE_PATH);

        return $src;
    }
1329833
private function preserveTransparency($image)
    {
        $transparencyColor = array(0, 0, 0);

        switch ($this->type) {
            case \IMAGETYPE_GIF:
                $color = imagecolorallocate($image, $transparencyColor[0], $transparencyColor[1], $transparencyColor[2]);

                imagecolortransparent($image, $color);
                imagetruecolortopalette($image, false, 256);
            break;

            case \IMAGETYPE_PNG:
                imagealphablending($image, false);

                $color = imagecolorallocatealpha($image, $transparencyColor[0], $transparencyColor[1], $transparencyColor[2], 0);

                imagefill($image, 0, 0, $color);
                imagesavealpha($image, true);
            break;
        }
    }
1159350
public function setDateFormat($formats) {

		if(false === is_array($formats)) {
			$formats = [$formats];
		}

		$this -> date_formats = $formats;

		return $this;
	}
1028803
public function setFormat($format)
    {
        if (!in_array($format, self::$formats)) {
            throw new ImageException('Invalid image format provided. Supported formats are [jpg, jpeg, png, gif].');
        }

        $this->format = $format;
    }
527055
function ($image) {
      var href;

      if ($image[0].nodeName === 'A') {
        href = $image.attr('href');
      } else {
        href = $image.closest('a').attr('href');
      }

      this.preload($image);

      if (href) {
        return href;
      }
      return $image.attr('src');
    }
1287132
public function withImages(array $images)
    {
        Assertion::allIsInstanceOf($images, ImageInterface::class);
        Assertion::lessOrEqualThan(\count($this->images), UrlInterface::IMAGE_MAX_COUNT);

        $instance = clone $this;

        $instance->images = $images;

        return $instance;
    }