create image file for this graph

@param Graph $graph graph to display
@return string                   filename
@throws UnexpectedValueException on error
@uses GraphViz::createScript()
349997
public function createImageFile(Graph $graph)
    {
        $script = $this->createScript($graph);
        // var_dump($script);

        $tmp = tempnam(sys_get_temp_dir(), 'graphviz');
        if ($tmp === false) {
            throw new UnexpectedValueException('Unable to get temporary file name for graphviz script');
        }

        $ret = file_put_contents($tmp, $script, LOCK_EX);
        if ($ret === false) {
            throw new UnexpectedValueException('Unable to write graphviz script to temporary file');
        }

        $ret = 0;

        $executable = $this->getExecutable();
        system(escapeshellarg($executable) . ' -T ' . escapeshellarg($this->format) . ' ' . escapeshellarg($tmp) . ' -o ' . escapeshellarg($tmp . '.' . $this->format), $ret);
        if ($ret !== 0) {
            throw new UnexpectedValueException('Unable to invoke "' . $executable .'" to create image file (code ' . $ret . ')');
        }

        unlink($tmp);

        return $tmp . '.' . $this->format;
    }
903016
public function createGraph($graph)
    {
        // Write the dot source to a temporary file
        $tempDot = tempnam(sys_get_temp_dir(), 'DOT_');
        $this->registerTempFile($tempDot);
        file_put_contents($tempDot, $graph);

        // Create component graph
//        $dotCommand = 'ccomps -x '.CommandUtility::escapeShellArgument($tempDot).' | dot -Nfontname=sans-serif -Efontname=sans-serif | gvpack -array_1 | neato -Tsvg ';
        $dotCommand = 'dot -Tsvg -Nfontname=sans-serif -Efontname=sans-serif '.CommandUtility::escapeShellArgument($tempDot);
        $output     = $returnValue = null;
        CommandUtility::exec($dotCommand, $output, $returnValue);

        return $returnValue ? '' : implode('', (array)$output);
    }
135345
private function exportGraph(NestedGraph $graph): array
	{
		$nodes = [];
		foreach ($graph->getNodes() as $node) {
			$nodeJson = [
				'id' => $this->prefix . $node->getId(),
				'graph' => $node->hasNestedGraph() ? $this->exportGraph($node->getNestedGraph()) : null,
				'attrs' => ($this->nodeAttrsProcessor)($node, $node->getAttributes()),
			];
			if ($nodeJson !== null) {
				$nodes[] = $nodeJson;
			}
		}

		$edges = [];
		foreach ($graph->getEdges() as $edge) {
			$edgeJson = [
				'id' => $this->prefix . $edge->getId(),
				'start' => $this->prefix . $edge->getStart()->getId(),
				'end' => $this->prefix . $edge->getEnd()->getId(),
				'attrs' => ($this->edgeAttrsProcessor)($edge, $edge->getAttributes()),
			];
			if ($edgeJson !== null) {
				$edges[] = $edgeJson;
			}
		}

		return ($this->graphProcessor)($graph, [
			'layout' => 'dagre',
			'nodes' => $nodes,
			'edges' => $edges,
		]);
	}
544385
public function createGraph()
    {
        $newgraph = $this->graph->createGraphCloneEdgeless();

        foreach ($this->graph->getEdges() as $edge) {
            if (!($edge instanceof EdgeDirected)) {
                throw new UnexpectedValueException('Edge is undirected');
            }

            $flow = $edge->getFlow();
            if ($flow === NULL) {
                throw new UnexpectedValueException('Flow not set');
            }

            $capacity = $edge->getCapacity();
            if ($capacity === NULL) {
                throw new UnexpectedValueException('Capacity not set');
            }

            // capacity is still available, clone remaining capacity into new edge
            if ($this->keepNullCapacity || $flow < $capacity) {
                $newEdge = $newgraph->createEdgeClone($edge)->setFlow(0)->setCapacity($capacity - $flow);

                if ($this->mergeParallelEdges) {
                    $this->mergeParallelEdges($newEdge);
                }
            }

            // flow is set, clone current flow as capacity for back-flow into new inverted edge (opposite direction)
            if ($this->keepNullCapacity || $flow > 0) {
                $newEdge = $newgraph->createEdgeCloneInverted($edge)->setFlow(0)->setCapacity($flow);

                // if weight is set, use negative weight for back-edges
                if ($newEdge->getWeight() !== NULL) {
                    $newEdge->setWeight(-$newEdge->getWeight());
                }

                if ($this->mergeParallelEdges) {
                    $this->mergeParallelEdges($newEdge);
                }
            }
        }

        return $newgraph;
    }
96467
protected function createEmptyNode($name, $graph)
    {
        $node = Node::create($name);
        $node->setFontColor('gray');
        $node->setLabel($name);
        $graph->setNode($node);

        return $node;
    }
975065
def prepare_filename_graph!
      @filename_graph = {}
      @encountered_graph.each do |filename, encountered_classes|
        dependent_class_names =
          if @definition_graph[filename].nil?
            encountered_classes
          else
            class_names_defined_in_file = @definition_graph[filename].keys
            # all superclass names that this file depends on
            class_names_dependent_by_superclass = @definition_graph[filename].values.compact - class_names_defined_in_file
            class_names_dependent_by_use = encountered_classes - class_names_defined_in_file
            class_names_dependent_by_superclass + class_names_dependent_by_use
          end
        dependent_class_names.each do |dep|
          dependent_definition_fname = @definition_graph.detect { |fname, hash| hash.has_key?(dep) }.first rescue nil
          if dependent_definition_fname
            @filename_graph[filename] ||= []
            unless @filename_graph[filename].include?(dependent_definition_fname)
              @filename_graph[filename] << dependent_definition_fname
            end
          end
        end
      end
    end
745655
protected function writeGraphHeader()
    {
        $nodeAttributes = array(
            'fontname'  => "Verdana",
            'fontsize'  => 8,
            'shape'     => "none",
            'margin'    => 0,
            'fillcolor' => '#FEFECE',
            'style'     => 'filled',
        );

        $edgeAttributes = array(
            'fontname'  => "Verdana",
            'fontsize'  => 8,
        );

        $indent = 1;

        $graph  = $this->formatLine('digraph ' . $this->graphId . ' {');
        $graph .= $this->formatLine('overlap = false;', $indent);
        $graph .= $this->formatLine('node [' . $this->attributes($nodeAttributes) . '];', $indent);
        $graph .= $this->formatLine('edge [' . $this->attributes($edgeAttributes) . '];', $indent);

        return $graph;
    }
754669
public function createGraphGroups()
    {
        $colors = $this->getColors();

        $graph = $this->graph->createGraphClone();
        foreach ($graph->getVertices()->getMap() as $vid => $vertex) {
            $vertex->setGroup($colors[$vid]);
        }

        return $graph;
    }
1203042
public function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $link = '')
    {
        if (preg_match("/\.png$/i", $file) || strtolower($type) == "png") {
            $file = $this->fixInterlacedPNG($file);

            // This may return a temp without a png extension
            $type = "png";
        }

        return parent::Image($file, $x, $y, $w, $h, $type, $link);
    }
243770
public function write($buffer)
    {
        $result = fwrite($this->fileHandle, $buffer, strlen($buffer));
        if ($result === false) {
            throw new \UnexpectedValueException(sprintf('Failed to write buffer into the file [ %s ].', $this->file));
        }
    }
1282038
public function create($args)
    {
        $args = wp_slash($args);
        $id   = wp_insert_post($args);

        if (is_wp_error($id)) {
            throw new UnexpectedValueException(sprintf('[W603] Failed creating new content: %s', $id->get_error_message()));
        }

        return $this->get($id);
    }
133735
protected function createResource($data, $path)
    {
        //if the GD Library is not installed
        if (!function_exists('gd_info')) {
            //throw error
            throw ImageException::forGDNotInstalled();
        }

        # imagecreatefromgd — Create a new image from GD file or URL
        # imagecreatefromgif — Create a new image from file or URL
        # imagecreatefromjpeg — Create a new image from file or URL
        # imagecreatefrompng — Create a new image from file or URL
        # imagecreatefromstring — Create a new image from the image stream in the string
        # imagecreatefromwbmp — Create a new image from file or URL
        # imagecreatefromxbm — Create a new image from file or URL
        # imagecreatefromxpm — Create a new image from file or URL

        $resource = false;

        if (!$path) {
            return imagecreatefromstring($data);
        }

        //depending on the extension lets load
        //the file using the right GD loader
        switch ($this->type) {
            case 'gd':
                $resource = imagecreatefromgd($data);
                break;
            case 'gif':
                $resource = imagecreatefromgif($data);
                break;
            case 'jpg':
            case 'jpeg':
            case 'pjpeg':
                $resource = imagecreatefromjpeg($data);
                break;
            case 'png':
                $resource = imagecreatefrompng($data);
                break;
            case 'bmp':
            case 'wbmp':
                $resource = imagecreatefromwbmp($data);
                break;
            case 'xbm':
                $resource = imagecreatefromxbm($data);
                break;
            case 'xpm':
                $resource = imagecreatefromxpm($data);
                break;
        }

        //if there is no resource still
        if (!$resource) {
            //throw error
            ImageException::forInvalidImageFile($path);
        }

        return $resource;
    }
1179007
protected function artFile($art)
    {
        $files = $this->fileSearch($art, '[^' . \DIRECTORY_SEPARATOR . ']*$');

        if (count($files) === 0) {
            $this->addDir(__DIR__ . '/../../ASCII');
            $files = $this->fileSearch($this->default_art, '.*');
        }

        if (count($files) === 0) {
            throw new UnexpectedValueException("Unable to find an art file with the name '{$art}'");
        }

        return reset($files);
    }
662286
public function dump(Graph $graph, $file, $format = PlantUML::FORMAT_TXT)
    {
        $format = $format ?: self::FORMAT_TXT;

        try {
            $content = implode(PHP_EOL, $graph->toArray()) . PHP_EOL;

            if (self::FORMAT_UML === $format) {
                $url = sprintf('http://www.plantuml.com/plantuml/uml/%s', $this->urlEncode($content));

                if (false !== fwrite($file, $url . PHP_EOL)) {
                    return fclose($file);
                }

                return false;
            }

            if (self::FORMAT_TXT === $format) {
                if (false !== fwrite($file, $content)) {
                    return fclose($file);
                }

                return false;
            }

            if (in_array($format, [self::FORMAT_PNG, self::FORMAT_SVG, self::FORMAT_ATXT, self::FORMAT_UTXT], true)) {
                if (null === $this->java) {
                    return false;
                }

                $prefix = sys_get_temp_dir() . '/' . uniqid();
                $txtPath = $prefix . '.txt';
                $pngPath = $prefix . '.' . $format;

                $clean = function () use ($txtPath, $pngPath) {
                    $this->fs->remove([$txtPath, $pngPath]);
                };

                $this->fs->dumpFile($txtPath, $content);

                $builder = new ProcessBuilder();
                $builder
                    ->add($this->java)
                    ->add('-jar')
                    ->add(__DIR__ . '/../Resources/lib/plantuml.1.2017.19.jar')
                    ->add($txtPath);

                if (self::FORMAT_SVG === $format) {
                    $builder->add('-tsvg');
                }

                if (self::FORMAT_ATXT === $format) {
                    $builder->add('-txt');
                }

                if (self::FORMAT_UTXT === $format) {
                    $builder->add('-utxt');
                }

                $plantUml = $builder->getProcess();

                $plantUml->run();

                if ($plantUml->isSuccessful()) {
                    if (false !== $png = fopen($pngPath, 'r')) {
                        if (0 !== stream_copy_to_stream($png, $file)) {
                            $clean();

                            return fclose($file);
                        }
                    }
                } else {
                    $this->logger->error($plantUml->getErrorOutput());
                }

                $clean();

                return false;
            }

            return false;
        } catch (\Exception $e) {
            return false;
        }
    }
876262
public function buildPlot( $config, $data )
	{
		$graphClass	= $config['type'];
		if( is_string( UI_Image_Graph_Components::getConfigValue( $config, 'data' ) ) )
		{
			if( isset( $data[$config['data']] ) )
			{
				if( !$data[$config['data']] )
					return NULL;
				$graphData	= $data[$config['data']];
			}
			else if( $config['data'] )
				throw new Exception( 'Data source "'.$config['data'].'" is not available.' );
			else
				return NULL;
		}
		else
			$graphData	= array_fill( 0, count( $data['x'] ), $config['data'] );

		$legend		= UI_Image_Graph_Components::getConfigValue( $config, 'legend' );
		$color		= UI_Image_Graph_Components::getConfigValue( $config, 'color' );
		$weight		= UI_Image_Graph_Components::getConfigValue( $config, 'weight' );
		$fillColor	= UI_Image_Graph_Components::getConfigValue( $config, 'fill.color' );

		$graphType	= new $graphClass( $graphData );

		if( $legend )
			$graphType->setLegend( $legend );
		if( $color )
			$graphType->setColor( $color );
		if( $weight )
			$graphType->setWeight( $weight );
		if( $fillColor )
			$graphType->setFillColor( $fillColor );

		UI_Image_Graph_Components::setValue( $graphType, $config );
		UI_Image_Graph_Components::setMark( $graphType, $config );
		return $graphType;
	}
210672
public function set($filename)
    {
        $this->image = null;
        $this->filename = $filename;

        $info = getimagesize($this->filename);

        if (empty($info)) {
            throw new UnexpectedValueException('Failed to get image dimensions');
        }

        $this->width = $info[0];
        $this->height = $info[1];
        $this->format = preg_replace('/^image\//', '', $info['mime']);
        $this->image = $this->callFunction('imagecreatefrom', $this->format, array($this->filename));

        if (!is_resource($this->image)) {
            throw new UnexpectedValueException('Image file handle is not a valid resource');
        }

        imagesavealpha($this->image, true);
        imagealphablending($this->image, true);

        return $this;
    }
616738
function saveGraphSONSync(graph, filename) {
        var FileOutputStream = Tinkerpop.autoImport('FileOutputStream');
        var stream = new FileOutputStream(filename);
        var builder = Tinkerpop.GraphSONWriter.build();
        var mapper = _newGraphSONMapperSync();
        builder.mapper(mapper);
        var writer = builder.create();
        writer.writeGraph(stream, graph);
        return graph;
    }