Output the image to either the browser or a file.

@access private
@param string $filename [Optional] Path to save image
@param bool $output [Optional] true to output the image.
@return \GImage\Image | resource
420672
private function outputBuffer($filename = null, $output = false)
    {
        if (!$this->resource) {
            return $this;
        }

        if ($output) {
            $filename = null;
        } elseif (empty($filename) && $this->isLocal()) {
            $filename = $this->filename;
        } elseif (empty($filename) && $this->isExternal()) {
            $filename = $this->name;
        }

        if ($output) {
            header('Content-type: ' . $this->mimetype);
            ob_start();
        }

        $this->outputBufferByImage($filename, $this->quality);

        if ($output) {
            ob_end_flush();
        }

        if (!$this->preserve) {
            $this->destroy();
        }

        return $this;
    }
245527
protected function outputFileCreation(array &$output)
    {
        if (file_exists($this->filename)) {
            $output[] = ['status' => 'ok', 'operation' => 'overwriting', 'file' => $this->filename];
        } else {
            $output[] = ['status' => 'ok', 'operation' => 'creating', 'file' => $this->filename];
        }

        return $this;
    }
249179
private function _getImagine(OutputInterface $output)
    {
        // Use Imagick extension by default
        if (extension_loaded('imagick') && class_exists("Imagick"))
        {
            $output->writeln('Imagick library is used!');
            return new \Imagine\Imagick\Imagine();
        }
        // fall back to GD
        if (extension_loaded('gd') && function_exists('gd_info'))
        {
            $output->writeln('GD library is used!');
            return new \Imagine\Gd\Imagine();
        }
        // Quit if can not find both extensions
        $output->writeln("<error>The `imagick` or `gd` extension must be loaded to generate image</error>");
        exit(1);
    }
287716
public function setOutput($output)
    {
        $this->output = $output;
        
        // Storing persistent opening
        if (true === $this->persistent) {
            self::$persistentBuffer[get_class($this).$this->binary.$this->movieFile] = $output;
        }
    }
380685
public function export_to_file($filename, $include_headers = true)
    {
        $fh = fopen($filename, 'w');
        if (false === $fh) {
            return false;
        }
        $export = $this->export($include_headers);
        $res = fwrite($fh, $export);
        if (false === $res) {
            return false;
        }

        return fclose($fh);
    }
639421
public function save($filename, $overwrite = false)
    {

        if ($this->html)
        {
            $this->snappy->generateFromHtml($this->html, $filename, $this->options, $overwrite);
        }
        elseif ($this->file)
        {
            $this->snappy->generate($this->file, $filename, $this->options, $overwrite);
        }

        return $this;
    }
879140
protected function execute(InputInterface $input, OutputInterface $output)
    {
        try {
            $output->writeln([
                'File Creator',
                '=====================',
            ]);

            $filename = $input->getArgument('filename');
            $this->create($filename);

            $output->writeln('Create <bg=yellow;>'.$filename.'.md</> <options=bold>Success!!!</>');
            $output->writeln('');
        } catch (Exception $e) {
            $output->writeln('<bg=red;>'.$e->getMessage().'</> <options=bold></>');
            $output->writeln('');
        }
    }
113406
private function createImages($output) {
        $image = array();
        
        foreach ($output as $key => $singleLine) {
            if (preg_match('/\(format/', $singleLine)) {
                $imageInfo  = $singleLine;
                $startPos   = strpos($imageInfo, "(") + 1;
                $endPos     = strpos($imageInfo, ")");
                $dataStr   = substr($imageInfo, $startPos, $endPos - $startPos);

                $dataExplode    = explode(",", $dataStr);
                $contentFormat  = explode(":", $dataExplode[0]);
                $format         = $contentFormat[1];
                $contentFormat  = explode(":", $dataExplode[1]);
                $type         = $contentFormat[1];

                $imageValue = $output[$key + 2];

                $exploded = explode(" ", $singleLine);
                $imagePath = array_shift($exploded);

                $image[] = new ZxingImage($imagePath, $imageValue, $format, $type);

            } else if(preg_match('/No barcode found/', $singleLine)) {
                
                $exploded = explode(" ", $singleLine);
                $imagePath = array_shift($exploded);
                $image[] = new ZxingBarNotFound($imagePath, 101, "No barcode found");
            }
        }

        return $image;
    }
186889
function cache_callback ( $output )
		{
			if ($hd = @fopen($this->cache_filename, 'w'))
			{
				fputs($hd,  $output);
				fclose($hd);
			}
			return $output;
		}
761685
public function output($return = true) {
        global $PAGE, $OUTPUT;
        static $template_printed;

        $this->initialise_javascript($PAGE);

        if (!empty(self::$nonjs)) {
            // return non js comments interface
            return $this->print_comments(self::$comment_page, $return, true);
        }

        $html = '';

        // print html template
        // Javascript will use the template to render new comments
        if (empty($template_printed) && $this->can_view()) {
            $html .= html_writer::tag('div', $this->template, array('style' => 'display:none', 'id' => 'cmt-tmpl'));
            $template_printed = true;
        }

        if ($this->can_view()) {
            // print commenting icon and tooltip
            $html .= html_writer::start_tag('div', array('class' => 'mdl-left'));
            $html .= html_writer::link($this->get_nojslink($PAGE), get_string('showcommentsnonjs'), array('class' => 'showcommentsnonjs'));

            if (!$this->notoggle) {
                // If toggling is enabled (notoggle=false) then print the controls to toggle
                // comments open and closed
                $countstring = '';
                if ($this->displaytotalcount) {
                    $countstring = '('.$this->count().')';
                }
                $collapsedimage= 't/collapsed';
                if (right_to_left()) {
                    $collapsedimage= 't/collapsed_rtl';
                } else {
                    $collapsedimage= 't/collapsed';
                }
                $html .= html_writer::start_tag('a', array(
                    'class' => 'comment-link',
                    'id' => 'comment-link-'.$this->cid,
                    'href' => '#',
                    'role' => 'button',
                    'aria-expanded' => 'false')
                );
                $html .= $OUTPUT->pix_icon($collapsedimage, $this->linktext);
                $html .= html_writer::tag('span', $this->linktext.' '.$countstring, array('id' => 'comment-link-text-'.$this->cid));
                $html .= html_writer::end_tag('a');
            }

            $html .= html_writer::start_tag('div', array('id' => 'comment-ctrl-'.$this->cid, 'class' => 'comment-ctrl'));

            if ($this->autostart) {
                // If autostart has been enabled print the comments list immediatly
                $html .= html_writer::start_tag('ul', array('id' => 'comment-list-'.$this->cid, 'class' => 'comment-list comments-loaded'));
                $html .= html_writer::tag('li', '', array('class' => 'first'));
                $html .= $this->print_comments(0, true, false);
                $html .= html_writer::end_tag('ul'); // .comment-list
                $html .= $this->get_pagination(0);
            } else {
                $html .= html_writer::start_tag('ul', array('id' => 'comment-list-'.$this->cid, 'class' => 'comment-list'));
                $html .= html_writer::tag('li', '', array('class' => 'first'));
                $html .= html_writer::end_tag('ul'); // .comment-list
                $html .= html_writer::tag('div', '', array('id' => 'comment-pagination-'.$this->cid, 'class' => 'comment-pagination'));
            }

            if ($this->can_post()) {
                // print posting textarea
                $textareaattrs = array(
                    'name' => 'content',
                    'rows' => 2,
                    'id' => 'dlg-content-'.$this->cid,
                    'aria-label' => get_string('addcomment')
                );
                if (!$this->fullwidth) {
                    $textareaattrs['cols'] = '20';
                } else {
                    $textareaattrs['class'] = 'fullwidth';
                }

                $html .= html_writer::start_tag('div', array('class' => 'comment-area'));
                $html .= html_writer::start_tag('div', array('class' => 'db'));
                $html .= html_writer::tag('textarea', '', $textareaattrs);
                $html .= html_writer::end_tag('div'); // .db

                $html .= html_writer::start_tag('div', array('class' => 'fd', 'id' => 'comment-action-'.$this->cid));
                $html .= html_writer::link('#', get_string('savecomment'), array('id' => 'comment-action-post-'.$this->cid));

                if ($this->displaycancel) {
                    $html .= html_writer::tag('span', ' | ');
                    $html .= html_writer::link('#', get_string('cancel'), array('id' => 'comment-action-cancel-'.$this->cid));
                }

                $html .= html_writer::end_tag('div'); // .fd
                $html .= html_writer::end_tag('div'); // .comment-area
                $html .= html_writer::tag('div', '', array('class' => 'clearer'));
            }

            $html .= html_writer::end_tag('div'); // .comment-ctrl
            $html .= html_writer::end_tag('div'); // .mdl-left
        } else {
            $html = '';
        }

        if ($return) {
            return $html;
        } else {
            echo $html;
        }
    }
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;

   }
799863
public function output($filename, $input)
    {
        $env = array('NODE_PATH' => $this->_settings['node_path']);

        $tmpfile = tempnam(sys_get_temp_dir(), 'miniasset_css_compressor');
        $this->generateScript($tmpfile, $input);

        $cmd = $this->_settings['node'] . ' ' . $tmpfile;
        return $this->_runCmd($cmd, '', $env);
    }
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;
        }
    }
69502
public function exportImage($keep_resource = false) {

		# export current resource image
		array_unshift($this->_output_options, $this->_image_resource, $this->_save_path);

		switch($this->_output_format) {
			case 'jpeg' :
			case 'jpg'  :
				if (!$this->_save_path) {
					header('content-type: image/jpeg');
				}

				$result = call_user_func_array('imagejpeg',  $this->_output_options);
				break;

			case 'png' :
				if (!$this->_save_path) {
					header('content-type: image/png');
				}

				$result = call_user_func_array('imagepng',  $this->_output_options);
				break;

			case 'gif' :
				if (!$this->_save_path) {
					header('content-type: image/gif');
				}

				$result = call_user_func_array('imagegif',  $this->_output_options);
				break;
		}

		// Reset output_options
		unset($this->_output_options[0], $this->_output_options[1]);
		$this->_output_options = array_values($this->_output_options);

		// Destroy Image
		if ($keep_resource === false) {
			$this->destroy();
		}

		// Exit incase of exporting to browser
		if (!$this->_save_path) {
			exit;
		}

		return ($result) ? ($this->_save_name  ? $this->_save_name : true) : false;
		# Method End
	}
1107593
public function outputFile($fileName = null, $format = 'Excel2007', $disconnect = true)
    {
        if (!$this->generated) {
            $this->generateFile($fileName, $format, $disconnect);
        }

        if (null === $fileName) {
            $fileName = $this->fileName;
        }

        $handler = fopen($this->filePath, 'r');

        header('Content-Description: File Transfer');
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header(sprintf('Content-Disposition: attachment; filename=%s', $fileName));
        header('Content-Transfer-Encoding: chunked');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header(sprintf('Content-Length: %s', filesize($this->filePath)));

        // Send the content in chunks
        while (!feof($handler)) {
            echo fread($handler, 4096);
        }

        return true;
    }
112066
public function getOutputFilename($output)
	{
		// default behaviour / backwards compatibility
		$outputDir = $output;
		$outputFilename = $this->getDefaultOutputFilename();

		// Find out if a .htm(l) filename has been given in the output argument.
		if ($this->endsWith($output, ".htm") || $this->endsWith($output, ".html")) {
			$outputDir = dirname($output);
			$outputFilename = basename($output);
		}

		return $outputDir . DIRECTORY_SEPARATOR . $outputFilename;
	}
840412
final public function saveImage($filename)
	{
		$extension = pathinfo($filename, PATHINFO_EXTENSION);

		if (! is_string($extension)) {
			$extension = image_type_to_extension($this->_image_type);
			$filename .= ".{$extension}";
		}

		switch(strtolower($extension))
		{
			case 'jpeg':
			case 'jpg':
				return $this->imageJPEG($filename);
				break;

			case 'png':
				return $this->imagePNG($filename);
				break;

			case 'gif':
				return $this->imageGIF($filename);

			default:
				trigger_error('Invalid extension or not an image', E_USER_WARNING);
				return false;
		}
	}