Outputs an image to the desired image type.

@param  resource $image The image resource
@param  string   $type  The image mimetype

@return string
487642
public static function output($image, $type)
    {
        $parts = explode('/', $type);
        $func = 'image'.strtolower($parts[1]);
        if (!function_exists($func)) {
            return;
        }

        $args = null;

        switch ($parts[1]) {
            case 'jpeg':
                $args = array($image, null, 100);
                break;
            case 'png':
                $args = array($image, null, 9);
                break;
            case 'gif':
                $args = array($image, null);
                break;
            default:
                return;
        }
        ob_start();
        call_user_func_array($func, $args);
        $image = ob_get_clean();

        return $image;
    }
628356
public function run(Image $image)
    {
        $sharpen = $this->getSharpen();

        if ($sharpen !== null) {
            $image->sharpen($sharpen);
        }

        return $image;
    }
1329833
private function preserveTransparency($image)
    {
        $transparencyColor = array(0, 0, 0);

        switch ($this->type) {
            case \IMAGETYPE_GIF:
                $color = imagecolorallocate($image, $transparencyColor[0], $transparencyColor[1], $transparencyColor[2]);

                imagecolortransparent($image, $color);
                imagetruecolortopalette($image, false, 256);
            break;

            case \IMAGETYPE_PNG:
                imagealphablending($image, false);

                $color = imagecolorallocatealpha($image, $transparencyColor[0], $transparencyColor[1], $transparencyColor[2], 0);

                imagefill($image, 0, 0, $color);
                imagesavealpha($image, true);
            break;
        }
    }
713004
public function image($image)
    {
        $filePaths = loader()->getPublicDirs(true);
        $image = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $image);

        foreach ($filePaths as $filePath) {
            $filePath .= 'img' . DIRECTORY_SEPARATOR;

            if (is_file($filePath . $image)) {
                return path_to_url($filePath . $image);
                break;
            }

            unset($filePath);
        }
    }
752271
public function dataUrl($type = 'jpeg')
    {
        $type      = $this->getType($type);
        $imageFunc = 'image' . $type;

        ob_start();

        $imageFunc($this->newImage);

        $data = ob_get_contents();

        ob_end_clean();

        $this->destroyAll();

        $dataUrl = 'data:image/'. $type . ';base64,' . base64_encode($data);

        return $dataUrl;
    }
284169
public function run(Image $image)
    {
        $contrast = $this->getContrast();

        if ($contrast !== null) {
            $image->contrast($contrast);
        }

        return $image;
    }
639673
public function output($image_type = null, $quality = null)
    {
        $image_type = $image_type ?: $this->source_type;

        header('Content-Type: ' . image_type_to_mime_type($image_type));

        $this->save(null, $image_type, $quality);
    }
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)]));
		}
	}
573392
public static function get_type_from_mime_type($mimeType) {
        $types = [
            'image/jpeg' => 'jpg',
            'image/png' => 'png',
            'image/gif' => 'gif',
        ];
        if (isset($types[$mimeType])) return $types[$mimeType];
        throw new ImageException(sprintf('Unsupported MIME type: %s', $mimeType), ImageException::UNSUPPORTED_MIME_TYPE);
    }
496615
public function getImageCaption($image): ?string
    {
        if (null === ($file = $this->container->get('huh.utils.file')->getFileFromUuid($image))) {
            return null;
        }

        $meta = StringUtil::deserialize($file->getModel()->meta, true);

        if (!isset($meta[$GLOBALS['TL_LANGUAGE']]['caption'])) {
            return null;
        }

        return $meta[$GLOBALS['TL_LANGUAGE']]['caption'];
    }
1108699
public function display($type = 'jpeg')
    {
        $type = $this->getType($type);

        header('Content-Type: image/' . $type);

        if ($type === 'jpeg')
        {
            imageinterlace($this->newImage, true);
        }

        $imageFunc = 'image' . $type;
        $imageFunc($this->newImage);

        $this->destroyAll();

        return $this;
    }
1126155
public function getFormat(Image $image)
    {
        $allowed = [
            'gif' => 'image/gif',
            'jpg' => 'image/jpeg',
            'pjpg' => 'image/jpeg',
            'png' => 'image/png',
            'webp' => 'image/webp',
        ];

        if (array_key_exists($this->fm, $allowed)) {
            return $this->fm;
        }

        if ($format = array_search($image->mime(), $allowed, true)) {
            return $format;
        }

        return 'jpg';
    }
1000109
public static void output(BufferedImage image, OutputStream out)
            throws IOException {
        ImageIO.write(image, "JPEG", out);
    }
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' );
		}
	}
1208814
public function optimize(Image $image): Image
    {
        $binary = $this->manipulate($image->getBinary(), 'optimize', $this->optimizationParams);

        return $image->modify($binary);
    }
597849
public function output($type = 'jpg', $quality = 75)
        {
            if($type == 'jpg' && (imagetypes() & IMG_JPG)) {
                header("Content-Type: image/jpeg");
                imagejpeg($this->im, null, $quality);
                return true;
            } elseif($type == 'png' && (imagetypes() & IMG_PNG)) {
                header("Content-Type: image/png");
                imagepng($this->im);
                return true;
            } elseif($type == 'gif' && (imagetypes() & IMG_GIF)) {
                header("Content-Type: image/gif");
                imagegif($this->im);
                return true;
            } else
                return false;
        }
991786
public function setImage($image) {

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

		$file = new File($image);

		if(false === $file -> exists()) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be an existing image', __METHOD__), E_USER_ERROR);
		}

		if(false === in_array(exif_imagetype($image), [IMAGETYPE_JPEG, IMAGETYPE_PNG])) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be an valid image (jpg, jpeg or png)', __METHOD__), E_USER_ERROR);
		}

		$this -> image = $file;

		return $this;
	}