Outputs the image stream to the browser.

@return $this

@throws \RuntimeException Thrown if $this->image is not a valid image
resource.
490581
public function render()
    {
        if (!is_resource($this->image)) {
            throw new \RuntimeException(
                'Attempt to render invalid resource as image.'
            );
        }

        header('Content-type: image/png');
        imagepng($this->image, null, 9, PNG_ALL_FILTERS);

        return $this;
    }
113724
public function withLocalScope()
    {
        if ($this->isClosed()) {
            throw new \RuntimeException("The stream is closed");
        }
        
        if (!$this->isGlobal()) {
            return $this;
        }
        
        $stream = clone $this;
        
        fwrite($stream->handle, (string)$this);
        
        return $stream;
    }
544390
public function image() {
        $tree = Globals::getTree();
        $cid   = Filter::get('cid');
        $certificate = null;
        if(!empty($cid)) $certificate =  Certificate::getInstance($cid, $tree, null, $this->provider);
        
        $imageBuilder = new ImageBuilder($certificate);
        
        if (!empty(Filter::get('cb'))) {
            $imageBuilder->setExpireOffset($imageBuilder->getExpireOffset() * 7);
        }
        
        $imageBuilder
            ->setShowWatermark(Auth::accessLevel($tree) >= $this->module->getSetting('MAJ_SHOW_NO_WATERMARK', Auth::PRIV_HIDE))
            ->setFontMaxSize($this->module->getSetting('MAJ_WM_FONT_MAXSIZE', 18))
            ->setFontColor($this->module->getSetting('MAJ_WM_FONT_COLOR', '#4D6DF3'))
        ;
        
        $imageBuilder->render();
        
    }
732404
private function getImageData()
    {
        ob_start();
        imagegif($this->image);
        $output = ob_get_contents();
        ob_end_clean();
        imagedestroy($this->image);

        return $output;
    }
166612
protected function image()
    {
        $locator = Grav::instance()['locator'];

        $file = $this->get('filepath');

        // Use existing cache folder or if it doesn't exist, create it.
        $cacheDir = $locator->findResource('cache://images', true) ?: $locator->findResource('cache://images', true, true);

        // Make sure we free previous image.
        unset($this->image);

        $this->image = ImageFile::open($file)
            ->setCacheDir($cacheDir)
            ->setActualCacheDir($cacheDir)
            ->setPrettyName($this->getImagePrettyName());

        return $this;
    }
426441
public function read()
    {
        $read = $this->getStreams();
        $write = null;
        $except = null;
        $modified = stream_select($read, $write, $except, 0, 200000);

        if ($modified === false) {
            throw new \RuntimeException("stream_select() returned an error");
        }

        foreach ($read as $resource) {
            foreach ($this->messages as $message) {
                $this->readResource($message, $resource);
            }
        }
    }
831855
public function Image()
    {
        if ($this->ActionImage()) {
            return $this->ActionImage();
        }
        if ($this->Type == 'SiteTree') {
            return $this->SiteTree()->ActionImage();
        }
    }
350776
public function init()
    {
        $stream = @fopen($this->config['url'], 'a');
        if (!$stream) {
            throw new \RuntimeException(sprintf("Couldn't open resource '%s'", $this->config['url']));
        }

        $this->stream = $stream;

        if (!empty($this->config['lock']) && $this->config['lock'] === true && stream_supports_lock($this->stream)) {
            $this->useLocks = true;
        }
    }
685705
public function outputCurrentPlayerImage()
    {
        $playerNumber = $this->getCurrentPlayer();

        $image = imagecreate(250, 50);

        //set the background color of the image
        $color = $this->collectionOptions->getGeneralOptions()->getImagePlayer()['background_color'];
        imagecolorallocate($image, $color[0], $color[1], $color[2]);
        //set the color for the text
        $color = $this->collectionOptions->getGeneralOptions()->getImagePlayer()['font_color'];
        $fontColor = imagecolorallocate($image, $color[0], $color[1], $color[2]);

        //adf the string to the image
        $maxPlayer = $this->collectionOptions->getGeneralOptions()->getMaxPlayer();
        if ($maxPlayer > 0) {
            $text = sprintf('%s/%s Player Online', $playerNumber, $maxPlayer);
        } else {
            $text = sprintf('%s Player Online', $playerNumber);
        }

        $this->imageCenterString($image, 5, $text, $fontColor);

        imagepng($image);

        imagedestroy($image);
    }
622193
public function getImageResource()
    {
        // Get existing resource
        if ($this->image) {
            return $this->image;
        }

        // Load container
        $assetContainer = $this->getAssetContainer();
        if (!$assetContainer) {
            return null;
        }

        // Avoid repeat load of broken images
        $hash = $assetContainer->getHash();
        $variant = $assetContainer->getVariant();
        if ($this->hasFailed($hash, $variant)) {
            return null;
        }

        // Validate stream is readable
        // Note: Mark failed regardless of whether a failed stream is exceptional or not
        $error = self::FAILED_MISSING;
        try {
            $stream = $assetContainer->getStream();
            if ($this->isStreamReadable($stream)) {
                $error = null;
            } else {
                return null;
            }
        } finally {
            if ($error) {
                $this->markFailed($hash, $variant, $error);
            }
        }

        // Handle resource
        $error = self::FAILED_UNKNOWN;
        try {
            // write the file to a local path so we can extract exif data if it exists.
            // Currently exif data can only be read from file paths and not streams
            $path = tempnam(TEMP_PATH, 'interventionimage_');
            if ($extension = pathinfo($assetContainer->getFilename(), PATHINFO_EXTENSION)) {
                //tmpnam creates a file, we should clean it up if we are changing the path name
                unlink($path);
                $path .= "." . $extension;
            }
            $bytesWritten = file_put_contents($path, $stream);
            // if we fail to write, then load from stream
            if ($bytesWritten === false) {
                $resource = $this->getImageManager()->make($stream);
            } else {
                $this->setTempPath($path);
                $resource = $this->getImageManager()->make($path);
            }

            // Fix image orientation
            try {
                $resource->orientate();
            } catch (NotSupportedException $e) {
                // noop - we can't orientate, don't worry about it
            }

            $this->setImageResource($resource);
            $this->markSuccess($hash, $variant);
            $this->warmCache($hash, $variant);
            $error = null;
            return $resource;
        } catch (NotReadableException $ex) {
            // Handle unsupported image encoding on load (will be marked as failed)
            // Unsupported exceptions are handled without being raised as exceptions
            $error = self::FAILED_INVALID;
        } finally {
            if ($error) {
                $this->markFailed($hash, $variant, $error);
            }
        }
        return null;
    }
556468
public function outputCacheImage()
    {
        try {
            $this->setUrlPathImage();
            $this->setFileImage();
            $this->setDirectoryImage();
            $this->tryOutputImage();
            $this->checkCacheDirectoryImage();
            $this->applyActionsImage();
            $this->tryOutputImage();
        } catch (Exception $ex) {
            $this->response->outputError404(false);
        }
    }
406031
public function imageFactory()
    {
        if ($this->imageFactory === null) {
            $this->imageFactory = $this->createImageFactory();
        }

        return $this->imageFactory;
    }
212469
public function genImage()
    {
        $this->image = imagecreatetruecolor($this->getPxRatio() * 5, $this->getPxRatio() * 5);

        $bg = $this->getBgColor();
        if (!empty($bg)) {
            $background = imagecolorallocate($this->image, $bg[0], $bg[1], $bg[2]);
            imagefill($this->image, 0, 0, $background);
        } else {
            $transparent = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
            imagefill($this->image, 0, 0, $transparent);
            imagesavealpha($this->image, true);
        }
        $color = $this->getColor();
        $color = imagecolorallocate($this->image, $color[0], $color[1], $color[2]);
        foreach ($this->getArrayOfSquare() as $lineKey => $lineValue) {
            foreach ($lineValue as $colKey => $colValue) {
                if ($colValue) {
                    imagefilledrectangle($this->image, $colKey * $this->getPxRatio(), $lineKey * $this->getPxRatio(), ($colKey + 1) * $this->getPxRatio(), ($lineKey + 1) * $this->getPxRatio(), $color);
                }
            }
        }

        return $this->image;
    }
491472
public function open($image) {
		if (!file_exists($image)) {
			throw new \RuntimeException(sprintf('File `%s` does not exist!', $image));
		}
		$this->_image = $this->imagine()->open($image);
		return $this;
	}
980348
public function getImagineImage()
    {
        if (null === $this->imagineImage) {
            $app = Application::getFacadeApplication();
            $resource = $this->getFileResource();
            $mimetype = $resource->getMimeType();
            $imageLibrary = $app->make(ImagineInterface::class);

            switch ($mimetype) {
                case 'image/svg+xml':
                case 'image/svg-xml':
                case 'text/plain':
                    if ($imageLibrary instanceof \Imagine\Gd\Imagine) {
                        try {
                            $imageLibrary = $app->make('image/imagick');
                        } catch (Exception $x) {
                            $this->imagineImage = false;
                        } catch (Throwable $x) {
                            $this->imagineImage = false;
                        }
                    }
                    break;
            }

            if (null === $this->imagineImage) {
                $metadataReader = $imageLibrary->getMetadataReader();
                if (!$metadataReader instanceof ExifMetadataReader) {
                    if ($app->make('config')->get('concrete.file_manager.images.use_exif_data_to_rotate_images')) {
                        try {
                            $imageLibrary->setMetadataReader(new ExifMetadataReader());
                        } catch (NotSupportedException $e) {
                        }
                    }
                }
                try {
                    $this->imagineImage = $imageLibrary->load($resource->read());
                } catch (FileNotFoundException $e) {
                    $this->imagineImage = false;
                }
            }
        }

        return $this->imagineImage ?: null;
    }
498294
public function read()
    {
        if (!file_exists($this->path)) {
            throw new \RuntimeException('Could not read ' . $this->path);
        }
        return file_get_contents($this->path);
    }
17588
public function run()
    {
        MaterializeAsset::register($this->getView());
        return Html::tag(
            'div',
            Html::tag($this->tagName, $this->encodeLabel ? Html::encode($this->label) : $this->label, $this->options) . Html::tag('ul', $this->renderButtons()),
            $this->wrapOptions
        );
    }