Modifie la qualité de sortie des fichiers de type JPEG

@param integer $quality  Qualité. De 0 à 100
@throws \Exception
357616
public function setJpegQuality($quality)
  {
    if (!is_numeric($quality) ||
      $quality < 0 ||
      $quality > 100) {
      throw new \Exception('Qualité JPEG : valeur numérique attendue de 0 à 100');
    }
    $this->jpgQuality = $quality;
  }
1271361
public function Quality($quality)
    {
        // Generate variant key
        $variant = $this->owner->variantName(__FUNCTION__, $quality);

        // Instruct the backend to search for an existing variant and use the callback to provide it if it does not exist.
        return $this->owner->manipulateImage($variant, function (Image_Backend $backend) use ($quality) {
            $backendClone = clone $backend;
            $backendClone->setQuality($quality);

            return $backendClone;
        });
    }
1045092
public function save($file, $type = 'guess', $quality = 80)
    {
        if ($file) {
            $directory = dirname($file);

            if (!is_dir($directory)) {
                @mkdir($directory, 0777, true);
            }
        }

        if (is_int($type)) {
            $quality = $type;
            $type = 'jpeg';
        }

        if ($type == 'guess') {
            $type = $this->guessType();
        }

        if (!isset(self::$types[$type])) {
            throw new \InvalidArgumentException('Given type ('.$type.') is not valid');
        }

        $type = self::$types[$type];

        try {
            $this->init();
            $this->applyOperations();

            $success = false;

            if (null == $file) {
                ob_start();
            }

            if ($type == 'jpeg') {
                $success = $this->getAdapter()->saveJpeg($file, $quality);
            }

            if ($type == 'gif') {
                $success = $this->getAdapter()->saveGif($file);
            }

            if ($type == 'png') {
                $success = $this->getAdapter()->savePng($file);
            }

            if ($type == 'webp') {
                $success = $this->getAdapter()->saveWebP($file, $quality);
            }

            if (!$success) {
                return false;
            }

            return null === $file ? ob_get_clean() : $file;
        } catch (\Exception $e) {
            if ($this->useFallbackImage) {
                return null === $file ? file_get_contents($this->fallback) : $this->getCacheFallback();
            } else {
                throw $e;
            }
        }
    }
908480
private function validateImageMimeType()
    {
        $imageType = exif_imagetype($this->uploadFile->getTemporaryFilename());
        $mime = image_type_to_mime_type($imageType);
        if (!$imageType || !in_array($mime, parent::getAllowedMimeTypes())) {
            throw new \Exception("Uploaded image appears to be corrupt"); // @codeCoverageIgnore
        }
    }
926861
public function compress($quality)
    {

        $this->gdExtensionCheck();
        $newFile = $this->getFilePath();
        $file = $newFile;

        switch ($this->getExt()) {
            case 'jpg':
                $img = imagecreatefromjpeg($file);
                unlink($file);
                imagejpeg($img, $newFile, $quality);
                break;
            case 'png':

                if ($quality > 10) {
                    $quality = ceil(100 / 10);
                }
                $img = imagecreatefrompng($file);
                unlink($file);

                imagepng($img, $newFile, $quality);
                break;
            case 'gif':
                $img = imagecreatefromgif($file);
                unlink($file);

                imagepng($img, $newFile);
                break;
        }
        imagedestroy($img);

        return $this;
    }
395203
final public function render($quality = 75)
    {
        header("Content-type: ".image_type_to_mime_type($this->type));

        switch ($this->type) {
            case \IMAGETYPE_GIF:
                imagegif($this->image, null);
            break;

            case \IMAGETYPE_JPEG:
                imagejpeg($this->image, null, $quality);
            break;

            case \IMAGETYPE_PNG:
                imagepng($this->image, null, 9);
            break;

            default:
                throw new LogicException(sprintf('Can not create image from "%s"', $this->file));
        }

        $this->done();
        exit(1);
    }
293437
public function rotateImageRight(Image $file, $quality = 95)
	{
		$this->rotateImage($file, ImageProcessor\ImageRotator::ROTATE_RIGHT, $quality);
	}
1081562
public function rotateImage(Image $file, $rotationCount, $quality = 95)
	{
		if ( ! $file instanceof Image) {
			throw new Exception\RuntimeException('Image entity expected');
		}

		$filename = $this->getFilesystemPath($file);
		$rotator = $this->getImageRotator();
		$rotator->setSourceFile($filename)
				->setOutputFile($filename)
				->setOutputQuality($quality)
				->setRotationCount($rotationCount);
		$rotator->rotate();

		if ((abs($rotationCount) % 2) == 1) {
			$tmp = $file->getWidth();
			$file->setWidth($file->getHeight());
			$file->setHeight($tmp);

			$entityManager = $this->getDoctrineEntityManager();
			$entityManager->persist($file);
			$entityManager->flush();
		}

		$this->recreateImageSizes($file);
	}
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);
	}
1203088
public function thumb($thumbWidth, $thumbHeight, $isCut = true, $cutPlace = 5, $quality = 95, $thumbType = 'jpg') 
    {
        if (!in_array($thumbType, ['jpg', 'png', 'webp'])) {
            throw new Exception('thumb image type must be webp|jpg|png');
        }
	
        if($isCut) {
            return $this->thumbCutOut($thumbWidth, $thumbHeight, $cutPlace, $quality, $thumbType);
        } else {
            return $this->thumbUnCut($thumbWidth, $thumbHeight, $quality, $thumbType);
        }
    }
500844
public function getImageBlob($type = null, $quality = 95)
	{
		return $this->processor->getImageBlob($type, $this->normalizeImageQuality($quality));
	}
760601
public function output($quality = null)
    {
        header('Content-type: image/' . $this->original_info['format']);
        $this->save(-1, $quality);
        //die to stop execution
        die();
    }
789913
public function setJpegQuality($quality = null)
    {
        if ($quality) {
            $this->useQuality = true;
        }

        $this->quality = isset($quality)
            ? $quality
            : self::JPEG_QUALITY_DEFAULT;

        (is_numeric($this->quality) and $this->quality > 0 and $this->quality <= 100)
            or $this->raiseError('Quality not in range.');

        $this->log("Setting JPEG quality to {$this->quality}.");

        return $this;
    }
1167972
private function getQuality($quality, $extension) {

		if(false === ('-' . intval($quality) == '-' . $quality)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($quality)), E_USER_ERROR);
		}

		if(false === is_string($extension)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($extension)), E_USER_ERROR);
		}

		if(strtolower($extension) === 'png' && $quality > 9) {
			$quality = floor(($quality - 1) / 10);
		}

		return $quality;
	}
326193
protected function saveImage($filePath, Imagick $image, $compression_quality)
    {
        $image->setImageCompression(Imagick::COMPRESSION_JPEG);
        $image->setImageCompressionQuality($compression_quality);
        $image->stripImage();
        $image->writeImage($filePath);

        return $image;
    }
270098
public function saveImage($saveImageFilePath, $quality = null)
    {
        $quality = empty($quality) ? $this->config->offsetGet('quality') : $quality;
        $optimizerConfig = $this->config->offsetGet('optimizer');

        if ($this->driver->save($saveImageFilePath, $quality)) {
            if ($optimizerConfig === 'default') {
                $optimizer = new Optimizer();
                $optimizer->optimize($saveImageFilePath);
            } elseif ( ! empty($optimizerConfig[ 'factory' ])) {
                $factory = $optimizerConfig[ 'factory' ];
                $optimizer = new Optimizer();

                switch ($factory) {
                    case 'imageoptim';
                        $factory = new Imageoptim();
                        $factory->setUsername($optimizerConfig[ 'username' ]);
                        $optimizer->setImageFactory($factory);
                        break;
                }

                $optimizer->optimize($saveImageFilePath);
            }

            return true;
        }

        return false;
    }
721201
protected function makeImage($file = null, $quality = null)
  {
    $dir = dirname($file);
    if (!is_dir($dir)) {
      mkdir($dir, 0777, true);
    }

    switch ($this->getTypeByFile($file)) {
      case IMG_JPG:
        return imagejpeg($this->image, $file, $quality ? : static::QUALITY_JPG);
        break;
      case IMG_PNG:
        return imagepng($this->image, $file, $quality ? : static::QUALITY_PNG);
        break;
      case IMG_GIF:
        return imagegif($this->image, $file);
        break;
      default:
        Ex::ThrowError(Ex::BAD_TYPE);
    }
  }