图片转换为jpeg格式.
@param $file
@param int $quality
@return bool|mixed|string
546992
public static function image2Jpeg($file, $quality = 80)
    {
        try {
            if (is_file($file)) {
                return Image::open($file)->setCacheDir(dirname($file))->jpeg($quality);
            }
        } catch (Exception $e) {
        }
        return false;
    }
836432
protected function getTypeByFile($file)
  {
    switch (strtolower(pathinfo($file, PATHINFO_EXTENSION))) {
      case 'jpg':
      case 'jpeg':
        $type = IMG_JPG;
        break;
      case 'png':
        $type = IMG_PNG;
        break;
      case 'gif':
        $type = IMG_GIF;
        break;
      default:
        $type = false;
    }

    return $type;
  }
293437
public function rotateImageRight(Image $file, $quality = 95)
	{
		$this->rotateImage($file, ImageProcessor\ImageRotator::ROTATE_RIGHT, $quality);
	}
420920
public function Quality($quality)
    {
        $quality = $this->castDimension($quality, 'Quality');
        $variant = $this->variantName(__FUNCTION__, $quality);
        return $this->manipulateImage($variant, function (Image_Backend $backend) use ($quality) {
            return $backend->setQuality($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;
	}
81812
public function save($filename = '', $quality = 100, $format = '')
    {
        if (empty($filename)) {
            $filename = $this->filename;
        }

        if (empty($format)) {
            $format = $this->format;
        }

        $arguments = array($this->image, $filename);

        if (in_array($format, array('jpg', 'jpeg'))) {
            $format = 'jpeg';
            imageinterlace($this->image, true);
            $arguments = array($this->image, $filename, round($quality));
        } else if ($format === 'png') {
            $arguments = array($this->image, $filename, round(9 * $quality / 100));
        }

        return $this->callFunction('image', $format, $arguments);
    }
320673
public static function output(&$image, $type = 'png', $filename = null, $quality = 100)
    {
        $type == 'jpg' && $type = 'jpeg';
        $imageFun = "image{$type}";
        if (is_null($filename)) { //输出到浏览器
            header("Content-type: image/{$type}");
            ($type == 'jpeg') ? $imageFun($image, null, $quality) : $imageFun($image);
        } else { //保存到文件
            ($type == 'jpeg') ? $imageFun($image, $filename, $quality) : $imageFun($image, $filename);
        }
        imagedestroy($image);
        exit();
    }
1262191
private function save($file)
    {
        $filename = $file['savepath'].$file['savename'];
        if (!$this->config['replace'] && is_file($filename)) { //不覆盖同名文件
            $this->errorInfo = "文件已经存在{$filename}";
            return false;
        }

        //如果是图片，检查格式
        if ( in_array(strtolower($file['extension']), ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf'])
            && false === getimagesize($file['tmp_name']) ) {
            $this->errorInfo = '非法图像文件';
            return false;
        }
        if (!move_uploaded_file($file['tmp_name'], $filename)) {
            $this->errorInfo = '文件上传错误!';
            return false;
        }

        if ($this->config['thumb'] && in_array(strtolower($file['extension']), ['gif', 'jpg', 'jpeg', 'bmp', 'png'])) {
            if ($image = getimagesize($filename)) {
                //生成缩略图
                $thumbPath = $this->config['thumbPath'] ? $this->config['thumbPath'] : dirname($filename);
                $thunbName = $this->config['thumbFile'] ? $this->config['thumbFile'] : $this->config['thumbPrefix'].basename($filename);
                Image::makeThumb($filename, $thumbPath.'/'.$thunbName, null, $this->config['thumbMaxWidth'], $this->config['thumbMaxHeight']);
            }
        }
        return true;
    }
291152
public function image( $file, $rule )
	{
		if( !($file instanceof File) ){
			return false;
		}
		if( $rule ){
			$rule = explode( ',', $rule );
			list( $width, $height, $type ) = getimagesize( $file->getRealPath() );
			if( isset( $rule[2] ) ){
				$imageType = strtolower( $rule[2] );
				if( 'jpeg' == $imageType ){
					$imageType = 'jpg';
				}
				if( image_type_to_extension( $type, false ) != $imageType ){
					return false;
				}
			}
			list( $w, $h ) = $rule;
			return $w == $width && $h == $height;
		} else{
			return in_array( $this->getImageType( $file->getRealPath() ), [1, 2, 3, 6] );
		}
	}
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);
    }
  }
698085
public function encode($format, $quality = null)
    {
        $this->toggleModified();

        $this->getInterventionImage()->encode($format, $quality);

        return $this;
    }
909277
public static function isImage($file)
    {
        if (!$v = getimagesize($file)) {
            return false;
        }
        return in_array($v[2], [IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP]);
    }
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);
    }
750843
private function open_image( $file )
	{
		$sfile = new SFile($file);

		// If $file isn't an array, we'll turn it into one
		if ( !is_array($file) ) {
			$file = array(
				'type'		=> $sfile->getMimeType(),
				'tmp_name'	=> $file
			);
		}

		$mime = $file['type'];
		$file_path = $file['tmp_name'];

		switch ( $mime )
		{
			case 'image/pjpeg': // IE6
			case 'image/jpeg':	$img = @imagecreatefromjpeg( $file_path );	break;
			case 'image/gif':	$img = @imagecreatefromgif( $file_path );	break;
			case 'image/png':	$img = @imagecreatefrompng( $file_path );	break;
			default:				$img = false;								break;
		}

		return $img;
	}
570876
public static function file( $file )
	{
		$params = array_merge( static::$params, array(
			'time' => time(),
			'fingerprint' => \CCSession::fingerprint(),
			'random' => CCStr::random(),
		));
		
		foreach( $params as $param => $value )
		{
			$file = str_replace( ':'.$param, $value, $file );
		}
		
		return $file;
	}
146288
protected function outputTo($path , $type='png', $quality=null)
	{
		switch ($type) {
			case 'jpg':
			case 'jpeg':
				if (is_null($quality)) $quality = 75;
				if (is_null($path)) header('Content-Type: image/jpeg');
				imagejpeg($this->_imageResource , $path , $quality );
				break;
			case 'gif':
				if (is_null($path)) header('Content-Type: image/gif');
				imagegif($this->_imageResource , $path );
				break;
			case 'png':
			default:
				if (is_null($quality)) $quality = 5;
				if (is_null($path)) header('Content-Type: image/png');
				imagepng($this->_imageResource , $path , $quality );
				break;
		}
		return true;
	}
949098
public function toString($type = 'jpg', $quality = 75)
        {
            ob_start();

            if($type == 'jpg' && (imagetypes() & IMG_JPG))
                imagejpeg($this->im, null, $quality);
            elseif($type == 'png' && (imagetypes() & IMG_PNG))
                imagepng($this->im);
            elseif($type == 'gif' && (imagetypes() & IMG_GIF))
                imagegif($this->im);

            return ob_get_clean();
        }