Analyzes the source image and stores gained information like
mime type / image type, width and height.

@param string $imageResource
@param string $imageType
@return void
14915
protected function _analyzeSourceImage($imageResource, $imageType) {
        $this->_params['sourceWidth'] = imagesx($imageResource);
        $this->_params['sourceHeight'] = imagesy($imageResource);
        $this->_params['mime'] = image_type_to_mime_type($imageType);
        $this->_params['type'] = $imageType;
    }
1060098
public function displayImage($fileType = 'jpg', $imageQuality = "100")
		# Author:     Jarrod Oberto
		# Date:       18-11-09
		# Purpose:    Display images directly to the browser
		# Param in:   The image type you want to display
		# Param out:
		# Reference:
		# Notes:
		#
	{

		if ( ! is_resource($this->imageResized))
		{
			if ($this->debug)
			{
				throw new Exception('saveImage: This is not a resource.');
			}
			else
			{
				throw new Exception();
			}
		}

		switch ($fileType)
		{
			case 'jpg':
			case 'jpeg':
				header('Content-type: image/jpeg');
				imagejpeg($this->imageResized, '', $imageQuality);
				break;
			case 'gif':
				header('Content-type: image/gif');
				imagegif($this->imageResized);
				break;
			case 'png':
				header('Content-type: image/png');

				// *** Scale quality from 0-100 to 0-9
				$scaleQuality = round(($imageQuality / 100) * 9);

				// *** Invert qualit setting as 0 is best, not 9
				$invertScaleQuality = 9 - $scaleQuality;

				imagepng($this->imageResized, '', $invertScaleQuality);
				break;
			case 'bmp':
				echo 'bmp file format is not supported.';
				break;

			// ... etc

			default:
				// *** No extension - No save.
				break;
		}


		//imagedestroy($this->imageResized);
	}
723329
public function imagecolorallocate($imageResource)
	{
		
		return imagecolorallocate(
			$imageResource,
			$this->_r,
			$this->_g,
			$this->_b
		);
		
	}
1148645
protected function setResourceToJsonTypeMapping(string $resourceType, string $jsonType): void
    {
        $this->resType2JsonType[$resourceType] = $jsonType;
    }
189974
private function _getImageTypeFromFileName($imageFile)
    {
        $ext = strtolower((string)pathinfo($imageFile, PATHINFO_EXTENSION));

        if ('jpg' === $ext or 'jpeg' === $ext) {
            return ImageType::JPEG;
        } else if ('gif' === $ext) {
            return ImageType::GIF;
        } else if ('png' === $ext) {
            return ImageType::PNG;
        } else if ('wbm' === $ext or 'wbmp' === $ext) {
            return ImageType::WBMP;
        } else {
            return ImageType::UNKNOWN;
        }
    }
5372
public function setImageType($type)
	{
		if ($type)
		{
			$this->image_type = $type;
		}

		if ($this->image_type == IMAGETYPE_PNG && $this->resource)
		{
			imagealphablending($this->resource, false);
			imagesavealpha($this->resource, true);
		}
	}
1264892
public void setResourceTypes(List<String> resourceTypes) {

        if ((resourceTypes != null) && !resourceTypes.isEmpty()) {
            addFilterQuery(CmsSearchField.FIELD_TYPE, resourceTypes, false, false);
        }
    }
70212
public function getImageConfig($imageType, $size, $property)
	{
		$config = $this->getConfigPrefix().'images.' . $imageType . '.';
		if ($size == 'original')
		{
			$config .= 'original.';
		}
		elseif (!is_null($size))
		{
			$config .= 'sizes.' . $size . '.';
		}
		$config .= $property;
		return \Config::get($config);
	}
512174
public function apply($imageRessource)
  {
    $startWidth = imagesx($imageRessource);
    $startHeight = imagesy($imageRessource);

    $xratio = $startWidth / $this->width;
    $yratio = $startHeight / $this->height;
    if ($xratio == $yratio) {
      if ($startHeight == $this->height && $startWidth == $this->width) {
        return $imageRessource;
      }
      $newWidth  = $this->width;
      $newHeight = $this->height;
    } else if($xratio > $yratio) {
      $newWidth  = $this->width;
      $newHeight = $startHeight * $newWidth / $startWidth;
    } else {
      $newHeight = $this->height;
      $newWidth  = $startWidth * $newHeight / $startHeight;
    }

    $resized = Image::createEmptyContainer($newWidth, $newHeight);
    imagecopyresampled($resized, $imageRessource, 0, 0, 0, 0, $newWidth, $newHeight, $startWidth, $startHeight);
    imagedestroy($imageRessource);
    return $resized;
  }
279019
protected function handleImageUpload($imageFile)
    {
        // resize the image with given option
        $image = $this->resizeImage($imageFile, $this->uploadFieldOptions);

        // save the uploaded file on disk
        return $this->saveImage($imageFile, $image);
    }
682997
public function write(MediaType $mediaType, ImageTemplate $template, $force = false)
    {
        $templateModifyTime = $template->getModifiedAt()->format('U');

        $templateWidth = $template->getWidth();
        if (!$templateWidth) {
            $templateWidth = 256;
        }
        $icon = $this->iconResolver->resolve($mediaType, $templateWidth);

        if (!$icon || !file_exists($icon)) {
            return;
        }

        $filePathClean = $this->getCleanFilename($template, $mediaType);
        $filePathWaiting = $this->getWaitingFilename($template, $mediaType);

        $dirClean = dirname($filePathClean);
        $dirWaiting = dirname($filePathWaiting);

        $filesystem = new Filesystem();

        if (!$filesystem->exists($dirClean)) {
            $filesystem->mkdir($dirClean);
        }
        if (!$filesystem->exists($dirWaiting)) {
            $filesystem->mkdir($dirWaiting);
        }

        if ($force || !$filesystem->exists($filePathClean)
                || !filesize($filePathClean)
                || filemtime($filePathClean) < $templateModifyTime) {
            $this->applier->apply($template, [], $icon, $filePathClean);

            if (!$filesystem->exists($filePathClean)) {
                throw new CreateDelegateFailedException('"Clean" delegate image not created: '.$filePathClean);
            }
        }

        if ($force || !$filesystem->exists($filePathWaiting)
                || !filesize($filePathWaiting)
                || filemtime($filePathWaiting) < $templateModifyTime) {
            if (substr($filePathClean, 0, 3) === 'jpg') {
                $source = imagecreatefromjpeg($filePathClean);
            } elseif (substr($filePathClean, 0, 3) === 'png') {
                $source = imagecreatefrompng($filePathClean);
            } else {
                $source = imagecreatefromgif($filePathClean);
            }

            $sx = imagesx($source);
            $sy = imagesy($source);
            $target = imagecreatetruecolor($sx, $sy);
            imagealphablending($target, true);
            imagesavealpha($target, true);
            $transparent = imagecolorallocatealpha($target, 255, 255, 255, 127);
            imagefilledrectangle($target, 0, 0, $sx, $sy, $transparent);
            imagecopy($target, $source, 0, 0, 0, 0, $sx, $sy);
            $waiting = imagecreatefrompng(
                $this->locator->locate('@PhlexibleMediaCacheBundle/Resources/public/icons/waiting.png')
            );
            $sx -= 16;
            $sy -= 16;
            imagecopy($target, $waiting, $sx, $sy, 0, 0, 16, 16);
            // $red   = imagecolorallocate($target, 235, 235, 235);
            // imagerectangle($target, $sx - 0, $sy - 1, $sx + 15, $sy + 16, $red);
            imagegif($target, $filePathWaiting);
            imagedestroy($source);
            imagedestroy($target);
            imagedestroy($waiting);

            if (!$filesystem->exists($filePathWaiting)) {
                throw new CreateDelegateFailedException('"Waiting" delegate image not created: '.$filePathWaiting);
            }
        }
    }
783925
protected function assertResource($resource)
    {
        if (!is_resource($resource) || get_resource_type($resource) !== 'gd') {
            throw new InvalidArgumentException('Invalid resource type.');
        }

        $width = imagesx($resource);
        $height = imagesy($resource);
        if ($width < 1 || $height < 1) {
            throw new InvalidImageDimensionException(
                sprintf('The resource image dimensions should be at least 1x1px. The resource image with %sx%spx dimensions given.', $width, $height)
            );
        }
    }
413034
public function resize(
        $imageData,
        $height,
        $width,
        $type = ElcodiMediaImageResizeTypes::FORCE_MEASURES
    ) {
        $originalResource = imagecreatefromstring($imageData);
        $originalWidth = imagesx($originalResource);
        $originalHeight = imagesy($originalResource);
        $dimensions = Dimensions::create(
            $originalWidth,
            $originalHeight,
            $width,
            $height,
            $type
        );

        $newResource = imagecreatetruecolor(
            $dimensions->getDstFrameX(),
            $dimensions->getDstFrameY()
        );

        $backgroundColor = imagecolorallocate($newResource, 255, 255, 255);
        imagefill($newResource, 0, 0, $backgroundColor);

        imagecopyresampled(
            $newResource,
            $originalResource,
            $dimensions->getDstX(),
            $dimensions->getDstY(),
            $dimensions->getSrcX(),
            $dimensions->getSrcY(),
            $dimensions->getDstWidth(),
            $dimensions->getDstHeight(),
            $dimensions->getSrcWidth(),
            $dimensions->getSrcHeight()
        );

        ob_start();
        imagejpeg($newResource);
        $content = ob_get_contents();
        ob_end_clean();

        return $content;
    }
141828
public static void write(Image image, String imageType, OutputStream out) throws IORuntimeException {
		write(image, imageType, getImageOutputStream(out));
	}
846010
protected function createImageResource($image, $imageInfo)
	{
		switch($imageInfo[2])
		{
			case IMAGETYPE_JPEG:
				return imagecreatefromjpeg($image);
				break;
			case IMAGETYPE_GIF:
				return imagecreatefromgif($image);
				break;
			case IMAGETYPE_PNG:
				return imagecreatefrompng($image);
				break;
			default:
				throw new RuntimeException(vsprintf('Unable to open [ %s ]. Unsupported image type.', [pathinfo($image, PATHINFO_EXTENSION)]));
		}
	}
484374
public function writeImage( $image, $file, $type) {
		switch ($type) {
			case 2:	//JPEG
			Imagejpeg( $image, $file);
			break;
			
			case 3:	//PNG
			Imagepng( $image, $file);
			break;
			
			default:
			$this->errorMsg="File format not supported.";
		}
	}
1205845
private function imageExists($imagePath, $imageSrc = null)
    {
        // If image name is sewhere parameter
        if (isset($imageSrc)) {
            // Form path to the image
            $imageFullPath = $this->formImagePath($imagePath, $imageSrc);
        } else {
            // Path was already set
            $imageFullPath = $imagePath;
        }

        // Call file service existence method
        return $this->fs->exists($imageFullPath);
    }