Turns on jpegoptim, which greatly reduces the size of jpeg images.

@param int $quality maximum quality

@return \self
760323
public function jpegoptim($quality = null)
    {
        return $quality === null ? $this->addItem('q', 'jpegoptim') : $this->addItem('q', 'jpegoptim', $quality);
    }
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;
    }
1239435
public static ImageOption jpegQualityOf(int quality) {
    if (quality < 1 || quality > 100) {
      throw new IllegalArgumentException("Quality has to be in the range from 1 to 100.");
    }

    return new ImageOption("q", Integer.toString(quality));
  }
542429
public function stringify( $quality = null, $type = null ) 
	{
		ob_start(); $this->stream( $quality, $type ); return ob_get_clean();
	}
410932
public function setMaxFileSize(int $value)
    {
        $this->maxFileSize = $value;

        $this->addValidationRule('max:' . $this->maxFileSize);

        return $this;
    }
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);
    }
  }
244309
public function save($imageTargetFilePath, $quality = 100)
    {
        $resampleImageResource =& $this->getResampleImageResource();
        $resampleImageResource->setCompressionQuality($quality);
        $resampleImageResource->stripimage();

        $extension = pathinfo($imageTargetFilePath, PATHINFO_EXTENSION);

        switch ($extension) {
            case 'jpg':
            case 'jpeg':
                $resampleImageResource->setImageFormat('jpg');
                break;

            case 'gif':
                $resampleImageResource->setImageFormat('gif');
                break;

            case 'png':
                $resampleImageResource->setImageFormat('png');
                $resampleImageResource->setImageAlphaChannel(\Gmagick::ALPHACHANNEL_ACTIVATE);
                $resampleImageResource->setBackgroundColor(new \GmagickPixel('transparent'));
                break;

            case 'webp':
                $resampleImageResource->setImageFormat('webp');
                $resampleImageResource->setImageAlphaChannel(\Gmagick::ALPHACHANNEL_ACTIVATE);
                $resampleImageResource->setBackgroundColor(new \GmagickPixel('transparent'));
                break;
        }

        try {

            $resampleImageResource->writeimage($imageTargetFilePath);

            return true;

        } catch (\GmagickException $e) {

            $this->errors[ $e->getCode() ] = $e->getMessage();

        }

        return false;
    }
290109
public function ToJPEG($quality = null, $backgroundColor = null)
	{
        if (!$quality) $quality = Config::inst()->get('ExtendedImage', 'get_jpeg_default_quality');
		if (!$backgroundColor) $backgroundColor = Config::inst()->get('ExtendedImage', 'get_jpeg_default_background_color');

		return $this->owner->getJPEGImage($quality, $backgroundColor);

	}
79614
public final function output( int $quality = 60, string $filename = null )
   {

      \header( 'Expires: 0' );
      \header( 'Cache-Control: private' );
      \header( 'Pragma: cache' );

      if ( empty( $filename ) )
      {
         $filename = \basename( $this->_file );
      }
      else
      {
         $filename = \basename( $filename );
      }

      if ( ! empty( $filename ) )
      {
         \header( "Content-Disposition: inline; filename=\"{$filename}\"" );
         $mime = MimeTypeTool::GetByFileName( $filename );
         \header( "Content-Type: {$mime}" );
         switch ( $mime )
         {
            case 'image/png':
               \imagepng( $this->r );
               break;
            case 'image/gif':
               \imagegif( $this->r );
               break;
            default:
               \imagejpeg( $this->r, null, $quality );
               break;
         }
         exit;
      }

      \header( "Content-Type: {$this->mimeType}" );

      switch ( $this->mimeType )
      {
         case 'image/png':
            \imagepng( $this->r );
            break;
         case 'image/gif':
            \imagegif( $this->r );
            break;
         default:
            \imagejpeg( $this->r, null, $quality );
            break;
      }

      exit;

   }
821321
protected function initDestImageResource() 
    {
    	// gif does not supports truecolor for resize
    	if (function_exists("ImageCreateTrueColor") && $this->getExtension() != 'gif') {
    		$this->destImageResource = ImageCreateTrueColor($this->destImageWidth, $this->destImageHeight);
    	} else {
    		$this->destImageResource = ImageCreate($this->destImageWidth, $this->destImageHeight);
    	}
    	
    	return $this;
    }
398434
public function trim($options) {
        if (isset($options['trim'])) return $this->trimPixels($options['trim']);
        if (isset($options['trim_perc'])) return $this->trimPerc($options['trim_perc']);
        return $this;
    }
586518
public function quality($quality = null)
    {
        if ($quality) {
            if (!$this->image) {
                $this->image();
            }

            $this->quality = $quality;

            return $this;
        }

        return $this->quality;
    }
909130
public function save($filename, $image_type = null, $quality = null)
	{
		$quality = (int) $quality;
		if (empty($quality)) {
			$quality = 100;
		}
		
		if (null === $image_type) {
			$image_type = $this->image_type;
		}
		
		switch ($image_type) {
			case 'gif':
			case IMAGETYPE_GIF:
				$success = imagegif($this->image, $filename);
				break;
				
			case 'png':
			case IMAGETYPE_PNG:
				$quality = 9 - round(($quality / 100) * 9);
				$success = imagepng($this->image, $filename, $quality);
				break;
				
			case 'jpeg':
			case 'jpg':
			case IMAGETYPE_JPEG:
			default:
				$success = imagejpeg($this->image, $filename, $quality);
				break;
		}
		
		return $success;
	}
134132
public function save( $fileName, $type = IMAGETYPE_PNG, $quality = 100 )
	{
		$this->saveImage( $fileName, $this->resource, $type, $quality );
	}
1204785
public function setJpegCompression($level)
    {
        if (is_int($level) || is_float($level) || (is_string($level) && is_numeric($level))) {
            $this->jpegCompression = min(max((int) $level, 0), 100);
        }

        return $this;
    }
1341303
public function limitSize($max) {
		// if the maximum is not numeric
		if(is_numeric($max)) {
			// set maximum
			$this->Limits->Size = intval($max);
		}
		// return self
		return($this);
	}
764728
public function process(Image $image, $format = null, $quality = null)
    {
        $this->setImage($image);
        $this->setFormat($format);
        $this->setQuality($quality);

        switch (strtolower($this->format)) {

            case 'data-url':
                $this->result = $this->processDataUrl();
                break;

            case 'gif':
            case 'image/gif':
                $this->result = $this->processGif();
                break;

            case 'png':
            case 'image/png':
            case 'image/x-png':
                $this->result = $this->processPng();
                break;

            case 'jpg':
            case 'jpeg':
            case 'image/jpg':
            case 'image/jpeg':
            case 'image/pjpeg':
                $this->result = $this->processJpeg();
                break;

            case 'tif':
            case 'tiff':
            case 'image/tiff':
            case 'image/tif':
            case 'image/x-tif':
            case 'image/x-tiff':
                $this->result = $this->processTiff();
                break;

            case 'bmp':
            case 'ms-bmp':
            case 'x-bitmap':
            case 'x-bmp':
            case 'x-ms-bmp':
            case 'x-win-bitmap':
            case 'x-windows-bmp':
            case 'x-xbitmap':
            case 'image/bmp':
            case 'image/ms-bmp':
            case 'image/x-bitmap':
            case 'image/x-bmp':
            case 'image/x-ms-bmp':
            case 'image/x-win-bitmap':
            case 'image/x-windows-bmp':
            case 'image/x-xbitmap':
                $this->result = $this->processBmp();
                break;

            case 'ico':
            case 'image/x-ico':
            case 'image/x-icon':
            case 'image/vnd.microsoft.icon':
                $this->result = $this->processIco();
                break;

            case 'psd':
            case 'image/vnd.adobe.photoshop':
                $this->result = $this->processPsd();
                break;

            case 'webp':
            case 'image/webp':
            case 'image/x-webp':
                $this->result = $this->processWebp();
                break;
                
            default:
                throw new \Hail\Image\Exception\NotSupportedException(
                    "Encoding format ({$format}) is not supported."
                );
        }

        $this->setImage(null);

        return $image->setEncoded($this->result);
    }