create base64-encoded image src target data to be used for html images

@param Graph $graph graph to display
@return string
@uses GraphViz::createImageData()
6189
public function createImageSrc(Graph $graph)
    {
        $format = $this->format;
        if ($this->format === 'svg' || $this->format === 'svgz') {
            $format = 'svg+xml;charset=' . $graph->getAttribute('graphviz.graph.charset', 'UTF-8');
        }

        return 'data:image/' . $format . ';base64,' . base64_encode($this->createImageData($graph));
    }
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;
    }
623005
public function &createGraph()
    {
        $engine = $this->charting_engine;
        if ($this->target_format == "HTML" || $this->target_format == "HTML2PDF") {
            $engine = $this->charting_engine_html;
        }

        if (ReporticoUtility::getRequestItem("target_format", "HTML") == "PDF") {
            $engine = $this->charting_engine;
        }

        // Cannot use two forms of charting in the same
        if (!class_exists("reportico_graph", false)) {
            switch ($engine) {
                case "NVD3":
                    $graph = new ChartNVD3($this, "internal");
                    break;

                case "FLOT":
                    $graph = new ChartFLOT($this, "internal");
                    break;

                case "JPGRAPH":
                    $graph = new ChrtJpgraph($this, "internal");
                    break;

                case "PCHART":
                default:
                    $graph = new ChartPchart($this, "internal");
                    break;
            }
        }

        $this->graphs[] = &$graph;
        return $graph;
    }
1187838
private function generateConcreteIndividualCode(EntityPackageBuilder $graph)
    {
        foreach ($graph->getEntityPackages() as $entity_package) {
            /* @var $entity_package EntityPackage */
            $this->writeIfVerbose(
                '    - Generating for package <info>' . $entity_package->getPackage()
                    ->getName() . '</info>'
            );
            foreach ($entity_package->getEntityContent()->getClasses() as $entity) {
                $this->writeIfVeryVerbose(
                    '        - Generating interface for <info>' . $entity->getName() . '</info>'
                );
                $this->reflection_generator->generate($entity);
            }
        }
    }
812159
private function createImage($path) {
		$mime = $this->mimeType($path);
      
		if ($mime[2] == 'jpg') {
			return imagecreatefromjpeg ($path);
		} else if ($mime[2] == 'png') {
			return imagecreatefrompng ($path);
		} else {
			return false; 
		} 
    }
91773
public function createScript(Graph $graph)
    {
        $alg = new Directed($graph);
        $directed = $alg->hasDirected();

        /*
         * The website [http://www.graphviz.org/content/dot-language] uses the term `ID` when displaying
         * the abstract grammar for the DOT language.
         * But the man pages for dot use the term `name` when describing the graph file language.
         */
        $name = $graph->getAttribute('graphviz.name');
        if ($name !== null) {
            $name = $this->escapeId($name) . ' ';
        }

        $script = ($directed ? 'di':'') . 'graph ' . $name . '{' . self::EOL;

        // add global attributes
        $globals = array(
            'graph' => 'graphviz.graph.',
            'node'  => 'graphviz.node.',
            'edge'  => 'graphviz.edge.',
        );

        foreach ($globals as $key => $prefix) {
            $bag = new AttributeBagNamespaced($graph, $prefix);

            if ($layout = $bag->getAttributes()) {
                $script .= $this->formatIndent . $key . ' ' . $this->escapeAttributes($layout) . self::EOL;
            }
        }

        $alg = new Groups($graph);
        // only append group number to vertex label if there are at least 2 different groups
        $showGroups = ($alg->getNumberOfGroups() > 1);

        if ($showGroups) {
            $gid = 0;
            $indent = str_repeat($this->formatIndent, 2);
            // put each group of vertices in a separate subgraph cluster
            foreach ($alg->getGroups() as $group) {
                $script .= $this->formatIndent . 'subgraph cluster_' . $gid++ . ' {' . self::EOL .
                           $indent . 'label = ' . $this->escape($group) . self::EOL;
                foreach($alg->getVerticesGroup($group)->getMap() as $vid => $vertex) {
                    $layout = $this->getLayoutVertex($vertex);

                    $script .= $indent . $this->escapeId($vid);
                    if($layout){
                        $script .= ' ' . $this->escapeAttributes($layout);
                    }
                    $script .= self::EOL;
                }
                $script .= '  }' . self::EOL;
            }
        } else {
            $alg = new Degree($graph);

            // explicitly add all isolated vertices (vertices with no edges) and vertices with special layout set
            // other vertices wil be added automatically due to below edge definitions
            foreach ($graph->getVertices()->getMap() as $vid => $vertex){
                $layout = $this->getLayoutVertex($vertex);

                if($layout || $alg->isVertexIsolated($vertex)){
                    $script .= $this->formatIndent . $this->escapeId($vid);
                    if($layout){
                        $script .= ' ' . $this->escapeAttributes($layout);
                    }
                    $script .= self::EOL;
                }
            }
        }

        $edgeop = $directed ? ' -> ' : ' -- ';

        // add all edges as directed edges
        foreach ($graph->getEdges() as $currentEdge) {
            $both = $currentEdge->getVertices()->getVector();
            $currentStartVertex = $both[0];
            $currentTargetVertex = $both[1];

            $script .= $this->formatIndent . $this->escapeId($currentStartVertex->getId()) . $edgeop . $this->escapeId($currentTargetVertex->getId());

            $layout = $this->getLayoutEdge($currentEdge);

            // this edge also points to the opposite direction => this is actually an undirected edge
            if ($directed && $currentEdge->isConnection($currentTargetVertex, $currentStartVertex)) {
                $layout['dir'] = 'none';
            }
            if ($layout) {
                $script .= ' ' . $this->escapeAttributes($layout);
            }

            $script .= self::EOL;
        }
        $script .= '}' . self::EOL;

        return $script;
    }
1070079
public function properties($graph)
    {
        if ($graph instanceof Graph) {
            $graph = $graph->getKey();
        }

        $url = UrlHelper::buildUrl(Urls::URL_DOCUMENT . '/_graphs', [$graph]);

        $result = $this->getConnection()->get($url);

        return $result->getJson();
    }
13346
function base64tpjpg(base64ImageData, filename) {
    var promise = new Promise(function(resolve, reject) {
        var base64Data = base64ImageData.replace(/^data:image\/\w+;base64,/, "");
        var dataBuffer = new Buffer(base64Data, 'base64');
        fs.writeFile(tmpimage, dataBuffer, function(err) {
            if (err) {
                reject(err);
            } else {
                execFile(mozjpeg, ['-outfile', filename, tmpimage], function(err) {
                    if (err) {
                        reject(err);
                    } else {
                        fs.unlink(tmpimage, function(err) {
                            resolve(filename);
                        });
                    }
                });
            }
        });
    });
    return promise;
}
251201
public function convertUrl($url) {
		$oembed = Oembed::get_oembed_from_url($url, false, $this->oembedOptions);
		if ($oembed) {
			return array('Title' => '', 'Content' => $oembed->forTemplate());
		} 

		$graph = OpenGraph::fetch($url);

		if ($graph) {
			foreach ($graph as $key => $value) {
				$data[$key] = Varchar::create_field('Varchar', $value);
			}
			if (isset($data['url'])) {
				return array('Title' => $graph->Title, 'Content' => MicroPost::create()->customise($data)->renderWith('OpenGraphPost'));
			}
		}

        if ($this->lookupLinks) {
            // get the post and take its <title> tag at the very least
            $service = new RestfulService($url);
            $response = $service->request();

            if ($response && $response->getStatusCode() == 200) {
                if (preg_match('/<title>(.*?)<\/title>/is', $response->getBody(), $matches)) {
                    $title = Convert::raw2xml(strip_tags(trim($matches[1])));
                    return array('Title' => $title, 'Content' => "<a href='$url'>$title</a>");
                }
            }
        }
	}
761980
public function dumpNodeTree(NestedGraph $graph, $indent = "", $withEdges = true)
	{
		if ($withEdges) {
			foreach ($graph->getEdges() as $edge) {
				echo $indent, "- ", $edge->getId(), ' (', $edge->getStart()->getId(), ' -> ', $edge->getEnd()->getId(), ")\n";
			}
		}

		foreach ($graph->getNodes() as $node) {
			echo $indent, "* ", $node->getId(), "\n";
			if ($node->hasNestedGraph()) {
				$this->dumpNodeTree($node->getNestedGraph(), $indent . "\t");
			}
		}
	}
1371100
protected function makeBase64Image($_base64_data) {

		$_img = base64_decode($_base64_data);
        $this->fileInfo['local_name'] = time().".png";
		$_filename = $this->getFileName($this->fileInfo['local_name']);
        $this->fileInfo['file_name'] = $_filename;
        $this->fileInfo['file_path'] = $this->config['upload_dir'].DIRECTORY_SEPARATOR.$_filename;
		if ( file_put_contents($this->fileInfo['file_path'], $_img) && file_exists($this->fileInfo['file_path']) ) {

            $size = getimagesize($this->fileInfo['file_path']);
            if ( ($this->config['max_width'] > 0 && $size[0] > $this->config['max_width'])
                || ($this->config['max_height'] > 0 && $size[1] > $this->config['max_height']) )  {

                $this->errNum = 9;
                return false;

            }
            $this->fileInfo['image_width'] = $size[0];
            $this->fileInfo['image_height'] = $size[1];
            //初始化mimeType
            $this->fileInfo['file_type'] = "image/png";
            $this->fileInfo['is_image'] = 1;
            $this->fileInfo['file_size'] = filesize($this->fileInfo['file_path']);

            $pathinfo = pathinfo($this->fileInfo['file_path']);
            $this->fileInfo['file_ext'] =  $pathinfo['extension'];
            $this->fileInfo['raw_name'] = $pathinfo['filename'];

            return $this->fileInfo;
		}
		$this->errNum = 8;

        return false;
	}
628441
public function toBase64() {
        ob_start ();
        $this->saveAs();
        $data = ob_get_contents();
        ob_end_clean();
        return 'data:image/'.$this->realType.';base64,'.base64_encode($data);
    }
1033360
public function saveGraph(
        \EasyRdf_Graph $graph,
        $uri = '',
        $headers = []
    ) {
        // Serialze the rdf.
        $turtle = $graph->serialise('turtle');

        // Checksum it.
        $checksum_value = sha1($turtle);

        // Set headers.
        $headers['Content-Type'] = 'text/turtle';
        $headers['digest'] = 'sha1=' . $checksum_value;

        // Save it.
        return $this->saveResource($uri, $turtle, $headers);
    }
95134
public function write(array $data, array $options)
    {
        if (!$this->getUtils()->isDotInstalled()) {
            throw ExportException::create(
                'Can\'t export to a Graphviz image because "dot" binary is not available. Verify that the ' .
                '"graphviz" package is installed on your system.'
            );
        }

        if (!isset($data['node']) || !($data['node'] instanceof NodeInterface)) {
            throw ValidationException::create(
                'Data attribute "node" must be an instance of IronEdge\Component\Graphs\Node\NodeInterface.'
            );
        }

        if (!isset($options['path']) || !is_string($options['path']) || $options['path'] === '') {
            throw ValidationException::create(
                'To be able to export this graph to a graphviz image, you must set option "path" with a string ' .
                'with the path to the target file.'
            );
        }

        /** @var NodeInterface $graph */
        $graph = $data['node'];
        $file = $options['path'];

        $graphvizCode = 'digraph ' . $graph->getId() . ' {' . PHP_EOL;
        $graphAttributes = $graph->getMetadataAttr('graphviz.nodeAttributes', []);

        if ($graphAttributes) {
            foreach ($graphAttributes as $k => $v) {
                $graphvizCode .= '  ' . $k . '=' . $v . ';' . PHP_EOL;
            }

            $graphvizCode .= PHP_EOL;
        }

        $graphvizCode .= $this->generateNodeCode($graph);

        $graphvizCode .= '}';

        $this->generateGraphvizOutputFile($graphvizCode, $file, ['targetType' => 'png']);
    }
96467
protected function createEmptyNode($name, $graph)
    {
        $node = Node::create($name);
        $node->setFontColor('gray');
        $node->setLabel($name);
        $graph->setNode($node);

        return $node;
    }
1164539
public function createNode($nodeId, $data = array())
    {

        $node = new Graph\Node($nodeId, $data);
        $node->setGraph($this);
        $this->addNode($node);

        return $node;
    }
490407
public function parse($graph, $data, $format = 'jsonld', $baseUri = null)
    {
        parent::checkParseParams($graph, $data, $format, $baseUri);

        foreach ($data as $quad) {
            $subject = (string)$quad->getSubject();

            if ('_:' === substr($subject, 0, 2)) {
                $subject = $this->remapBnode($subject);
            }

            $predicate = (string)$quad->getProperty();

            if ($quad->getObject() instanceof IRI) {
                $object = [
                    'type' => 'uri',
                    'value' => (string)$quad->getObject()
                ];

                if ('_:' === substr($object['value'], 0, 2)) {
                    $object = [
                        'type' => 'bnode',
                        'value' => $this->remapBnode($object['value'])
                    ];
                }
            } else {
                $object = [
                    'type' => 'literal',
                    'value' => $quad->getObject()->getValue()
                ];

                if ($quad->getObject() instanceof LanguageTaggedString) {
                    $object['lang'] = $quad->getObject()->getLanguage();
                } else {
                    $object['datatype'] = $quad->getObject()->getType();
                }
            }

            $this->addTriple($subject, $predicate, $object);
        }
    }