输出图片

@param resource $image 被载入的图片
@param string $type 输出的类型
@param string $filename 保存的文件名
@param int $quality jpeg保存的质量

@return void
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();
    }
139012
public function save($path, $type = null)
    {
        #imagepng() - Output a PNG image to either the browser or a file
        #imagegif() - Output image to browser or file
        #imagewbmp() - Output image to browser or file
        #imagejpeg() - Output image to browser or file
        
        if (!$type) {
            $type = $this->type;
        }

        switch ($type) {
            case 'gif':
                imagegif($this->resource, $path);
                break;
            case 'png':
                $quality = (100 - $this->quality) / 10;

                if ($quality > 9) {
                    $quality = 9;
                }

                imagepng($this->resource, $path, $quality);
                break;
            case 'bmp':
            case 'wbmp':
                imagewbmp($this->resource, $path, $this->quality);
                break;
            case 'jpg':
            case 'jpeg':
            case 'pjpeg':
            default:
                imagejpeg($this->resource, $path, $this->quality);
                break;

        }

        return $this;
    }
1023644
public function saveImage( $type = NULL )
	{
		if( !$this->source )
			throw new RuntimeException( 'No image loaded' );
		if( !$this->target )
			throw new RuntimeException( 'No modification applied' );
		if( !$this->targetUri )
			throw new RuntimeException( 'No target image URI set' );
		$type	= $type ? $type : $this->sourceInfo[2];
		switch( $type )
		{
			case IMAGETYPE_GIF:
				return imagegif( $this->target, $this->targetUri );
			case IMAGETYPE_JPEG:
				return imagejpeg( $this->target, $this->targetUri, $this->quality );
			case IMAGETYPE_PNG:
				return imagepng( $this->target, $this->targetUri );
			default:
				throw new Exception( 'Image Type "'.$type.'" is no supported' );
		}
	}
39844
public function addResource($resource, string $type = 'file'): void
    {
        if (is_array($resource)) {
            $this->addResourceArray($resource);
            return;
        }

        if (is_string($resource)) {
            switch ($type) {
                case 'json':
                    $this->addResourceString($resource);
                    break;
                case 'file':
                    $this->addResourceFile($resource);
                    break;
                default:
                    throw new \InvalidArgumentException("Invalid resource type");
            }
        }
    }
141828
public static void write(Image image, String imageType, OutputStream out) throws IORuntimeException {
		write(image, imageType, getImageOutputStream(out));
	}
414710
public function generateToJPEGImage($quality, $backgroundColor, $pathinfo, $type){
        $cacheFile = $this->owner->cacheToJPEGFilename($quality, $backgroundColor, $pathinfo);

        $backend = Injector::inst()->createWithArgs(Image::get_backend(), array(
            Director::baseFolder()."/" . $this->owner->Filename
        ));

        $backend = $backend->toJpeg($backgroundColor, $type);
        if($backend){
            $backend->setQuality($quality);
            $backend->writeTo(Director::baseFolder()."/" . $cacheFile);
        }
    }
1256601
public function finalFile($file, $type = 'images') {
		return isset($this->oss[$type]) ? $this->putFileToOss($file['name'], $file['tmp'], $type) : $file['src'];
	}
1153643
public function stream( $quality = null, $type = null ) 
	{
		$this->save( null, $quality, $type );
	}
454161
public static byte[] writeImageToBytes(BufferedImage image,
			String formatName, Float quality) throws IOException {
		byte[] bytes = null;
		if (quality != null) {
			bytes = compressAndWriteImageToBytes(image, formatName, quality);
		} else {
			bytes = writeImageToBytes(image, formatName);
		}
		return bytes;
	}
650226
public function rotateImage180(Image $file, $quality = 95)
	{
		$this->rotateImage($file, ImageProcessor\ImageRotator::ROTATE_180, $quality);
	}
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);
    }
  }
1218566
public function readImage( $file, $type) {
		switch ($type) {
			case 2:	//JPEG
			return(ImageCreateFromJPEG($file));
			break;
			
			case 3:	//PNG
			return(ImageCreateFromPNG($file));
			break;
			
			default:
			$this->errorMsg="File format not supported.";
			return(false);
		}
	}
1100094
protected function imageCreateFrom($type, $src, $func = null)
    {
        $func = strtolower('imageCreateFrom'.$type);

        return (is_callable($func)) ? $func($src) : null;
    }
1218885
public static void saveJpeg(Bitmap src, String fileName, int quality) throws ImageSaveException {
        save(src, fileName, Bitmap.CompressFormat.JPEG, quality);
    }
566415
function output($format = null, $quality = null) {
        // Determine quality
        $quality = $quality ? : $this->quality;
        // Determine mimetype
        switch (strtolower($format)) {
            case 'gif':
                $mimetype = 'image/gif';
                break;
            case 'jpeg':
            case 'jpg':
                imageinterlace($this->image, true);
                $mimetype = 'image/jpeg';
                break;
            case 'png':
                $mimetype = 'image/png';
                break;
            default:
                $info = (empty($this->imagestring)) ? getimagesize($this->filename) : getimagesizefromstring($this->imagestring);
                $mimetype = $info['mime'];
                unset($info);
                break;
        }
        // Output the image
        header('Content-Type: ' . $mimetype);
        switch ($mimetype) {
            case 'image/gif':
                imagegif($this->image);
                break;
            case 'image/jpeg':
                imageinterlace($this->image, true);
                imagejpeg($this->image, null, round($quality));
                break;
            case 'image/png':
                imagepng($this->image, null, round(9 * $quality / 100));
                break;
            default:
                throw new Exception('Unsupported image format: ' . $this->filename);
                break;
        }
    }
1305183
public function rotateImageLeft(Image $file, $quality = 95)
	{
		$this->rotateImage($file, ImageProcessor\ImageRotator::ROTATE_LEFT, $quality);
	}
741292
public function execute($image)
    {
        $format = $this->argument(0)->value();
        $quality = $this->argument(1)->between(0, 100)->value();

        $this->setOutput(\GuzzleHttp\Psr7\stream_for(
            $image->encode($format, $quality)->getEncoded()
        ));

        return true;
    }