Example #1
0
 /**
  * Create a SVGLineGraph
  *
  * @param int $startX
  * @param int $startY
  * @param int $maxY
  * @param int $maxX
  * @return SVGLineGraph
  */
 public static function getInstance($startX = 30, $startY = 50, $maxY = NULL, $maxX = NULL)
 {
     $svg = parent::getInstance(null, 'SVGLineGraph');
     $svg->startX = $startX;
     $svg->startY = $startY;
     $svg->maxY = $maxY;
     $svg->maxX = $maxX;
     return $svg;
 }
Example #2
0
 *
 * @author Eduardo Bonfandini
 *
 *-----------------------------------------------------------------------
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as published
 *   by the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, access
 *   http://www.fsf.org/licensing/licenses/lgpl.html or write to the
 *   Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *----------------------------------------------------------------------
 */
require_once "../svglib/svglib.php";
$svg = SVGDocument::getInstance();
#start a svgDocument using default (minimal) svg document
$svg->setTitle("Simple example");
#define the title
$rect = SVGRect::getInstance(0, 5, 'myRect', 228, 185, new SVGStyle(array('fill' => 'blue', 'stroke' => 'gray')));
#create a new rect with, x and y position, id, width and heigth, and the style
$svg->addShape($rect);
#add the rect to svg
$svg->output();
#output to browser, with header
Example #3
0
 * Blog: http://trialforce.nostaljia.eng.br
 *
 * Started at Mar 11, 2011
 *
 * @author Eduardo Bonfandini
 *
 *-----------------------------------------------------------------------
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as published
 *   by the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, access
 *   http://www.fsf.org/licensing/licenses/lgpl.html or write to the
 *   Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *----------------------------------------------------------------------
 */
require_once "../svglib/svglib.php";
#start a svgDocument using apple.svg as base document
$apple = SVGDocument::getInstance('resource/apple.svg');
$image = SVGDocument::getInstance('resource/image.svg');
#add some part of image.svg into apple.svg
$apple->addShape($image->path);
$apple->addShape($image->image);
$apple->output();
 *----------------------------------------------------------------------
 */
//to SVG convert
ini_set('max_execution_time', '0');
require_once "../svglib/svglib.php";
if ($_FILES) {
    $target_path = 'output/' . basename($_FILES['uploadedfile']['name']);
    $mime = $_FILES['uploadedfile']['type'];
    if ($_FILES['uploadedfile']['error']) {
        die('Error on upload.');
    }
    if ($mime != SVGDocument::HEADER) {
        die('Only SVG files can be converted.');
    }
    if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        $svg = SVGDocument::getInstance($target_path);
        echo '<embed style="border:solid 1px gray;" src="' . $target_path . '" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" /><br / >';
        $svg->asXML('output/test.svgz');
        //compacted svg
        $ok = $svg->export('output/upload.png');
        $svg->export('output/upload16x16.png', 16, 16, true);
        $svg->export('output/upload32x32.png', 32, 32, true);
        $svg->export('output/upload64x64.png', 64, 64, true);
        $svg->export('output/upload128x128.png', 128, 128, true);
        $svg->export('output/upload256x256.png', 256, 256, true);
        echo '<img src="output/upload.png"/><br/>';
        echo '<img src="output/upload16x16.png"/><br/>';
        echo '<img src="output/upload32x32.png"/><br/>';
        echo '<img src="output/upload64x64.png"/><br/>';
        echo '<img src="output/upload128x128.png"/><br/>';
        echo '<img src="output/upload256x256.png"/><br/>';
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, access
 *   http://www.fsf.org/licensing/licenses/lgpl.html or write to the
 *   Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * ----------------------------------------------------------------------
 */
require_once "../svglib/svglib.php";
$rotate = @$_REQUEST['rotate'];
//rotate the square using passed angle
$translate = @$_REQUEST['translate'];
//rotate the square using passed angle
$file = @$_REQUEST['file'];
//load the file passed
$fill = @$_REQUEST['fill'] ? @$_REQUEST['fill'] : 'red';
$stroke = @$_REQUEST['stroke'] ? @$_REQUEST['stroke'] : 'black';
$svg = SVGDocument::getInstance($file);
$style = new SVGStyle();
$style->setFill($fill);
$style->setStroke($stroke);
$rect = SVGRect::getInstance(50, 50, 'myRect', 100, 100, $style);
if ($rotate) {
    //uses the x and y properties to align the rect
    $rect->rotate($rotate, $rect->getX() * 2, $rect->getY() * 2);
}
if ($translate) {
    $translate = explode(',', $translate);
    $rect->translate($translate[0], $translate[1]);
}
$svg->addShape($rect);
$svg->output();
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, access
 *   http://www.fsf.org/licensing/licenses/lgpl.html or write to the
 *   Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * ----------------------------------------------------------------------
 */
require_once "../svglib/svglib.php";
#start a svgDocument using apple.svg as base document
$svg = SVGDocument::getInstance('resource/apple.svg');
#start a svgDocument using default (minimal) svg document
#$svg = SVGDocument::getInstance( ); //default
#define the title
$svg->setTitle("Adding elements");
#some possible svg functions
#$svg->getWidth();
#$svg->getHeight();
#$svg->getVersion();
#example of criation of an svg style
#$style = 'fill:#f2f2f2;stroke:#e1a100;';
#create a new rect with, x and y position, id, width and heigth, and the style
$rect = SVGRect::getInstance(0, 5, 'myRect', 228, 185, new SVGStyle(array('fill' => 'red', 'stroke' => 'blue')));
#$rect->style->setFill('#f2f2f2'); //still not work
#$rect->style->setStroke('#e1a100'); //still not work
$rect->setWidth($svg->getWidth());
 /**
  * Get SVG image from hard disk.
  * 
  * @param string $format
  * @return string SVG image or URL to PNG image
  */
 public function getImage($format = 'svg')
 {
     if (file_exists($this->filePath)) {
         $svg = SVGDocument::getInstance($this->filePath, 'CampanhaSVGDocument');
         if ($format == 'svg') {
             return $svg->asXML(null, false);
         } else {
             $filePath = preg_replace('/\\.svg$/', '.png', $this->filePath);
             $url = $this->baseUrl . basename($this->fileName, '.svg') . '.png';
             $svg->export($filePath);
             // resize image to browser size (75dpi)
             $img = WideImage::load($filePath);
             $img->resize($this->converter->maybeConvertTo75Dpi(static::width), $this->converter->maybeConvertTo75Dpi(static::height), 'outside')->saveToFile($filePath);
             return $url;
         }
     }
 }