/**
  * Export as SVG to image document using inkscape.
  *
  * It will save a temporary file on default system tempo folder.
  *
  * @param string $filename try to use complete path. Works better.
  * @param integer $width
  * @param integer $height
  *
  * @return boolean ?
  */
 public function exportInkscape($filename, $width = null, $height = null)
 {
     include_once 'inkscape.php';
     //support export using inkscape
     $format = SVGDocument::getFileExtension($filename);
     $inkscape = new Inkscape($this);
     $inkscape->setSize($width, $height);
     return $inkscape->export($format, $filename);
 }
Exemplo n.º 2
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();
Exemplo n.º 3
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
Exemplo n.º 4
0
 *----------------------------------------------------------------------
 */
//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/>';
Exemplo n.º 5
0
 /**
  * Export the object as xml text, OR xml file.
  *
  * If the file extension is svgz, the function will save it correctely;
  *
  * @param string $filename the file to save, is optional, you can output to a var
  * @return string the xml string if filename is not passed
  */
 public function asXML($filename = null)
 {
     //if is svgz use compres.zlib to load the compacted SVG
     if (SVGDocument::getFileExtension($filename) == self::EXTENSION_COMPACT) {
         //verify if zlib is installed
         if (!function_exists('gzopen')) {
             throw new Exception('GZip support not installed.');
             return false;
         }
         $filename = 'compress.zlib://' . $filename;
     }
     $xml = parent::asXML(null);
     //need to do it, if pass a null filename it return an error
     if ($filename) {
         return file_put_contents($filename, $xml);
     }
     return $xml;
 }
 *
 *   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();
        public function create_image_from_svg()
        {
            if (!isset($_POST['order_id']) || !isset($_POST['item_id']) || !isset($_POST['svg']) || !isset($_POST['title'])) {
                exit;
            }
            check_ajax_referer('fpd_ajax_nonce', '_ajax_nonce');
            require_once FPD_PLUGIN_ADMIN_DIR . '/inc/svglib/svglib.php';
            $order_id = trim($_POST['order_id']);
            $item_id = trim($_POST['item_id']);
            $svg = stripslashes(trim($_POST['svg']));
            $width = trim($_POST['width']);
            $height = trim($_POST['height']);
            $title = sanitize_title(trim($_POST['title']));
            //create fancy product orders directory
            if (!file_exists(FPD_ORDER_DIR)) {
                wp_mkdir_p(FPD_ORDER_DIR);
            }
            //create uploads dir
            $images_dir = FPD_ORDER_DIR . 'images/';
            if (!file_exists($images_dir)) {
                wp_mkdir_p($images_dir);
            }
            //shortcode order
            if (empty($item_id)) {
                $shortcode_dir = FPD_ORDER_DIR . 'images/_shortcode/';
                if (!file_exists($shortcode_dir)) {
                    wp_mkdir_p($shortcode_dir);
                }
                $item_dir = $shortcode_dir . $order_id . '/';
                if (!file_exists($item_dir)) {
                    wp_mkdir_p($item_dir);
                }
            } else {
                //create order dir
                $order_dir = $images_dir . $order_id . '/';
                if (!file_exists($order_dir)) {
                    wp_mkdir_p($order_dir);
                }
                //create item dir
                $item_dir = $order_dir . $item_id . '/';
                if (!file_exists($item_dir)) {
                    wp_mkdir_p($item_dir);
                }
            }
            $image_path = $item_dir . $title . '.svg';
            $image_exist = file_exists($image_path);
            header('Content-Type: application/json');
            try {
                $svg = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="' . $width . '" height="' . $height . '" xml:space="preserve">' . $svg . '</svg>';
                $svg_doc = new SVGDocument($svg);
                $svg_doc->asXML($image_path);
                $image_url = content_url(substr($image_path, strrpos($image_path, '/fancy_products_orders/')));
                echo json_encode(array('code' => $image_exist ? 302 : 201, 'url' => $image_url, 'title' => $title));
            } catch (Exception $e) {
                echo json_encode(array('code' => 500));
            }
            die;
        }
Exemplo n.º 8
0
 public function asXML($filename = NULL, $human = TRUE)
 {
     #clean fields that not has to be in svg
     unset($this->maxY);
     unset($this->maxX);
     unset($this->startX);
     unset($this->startY);
     unset($this->data);
     return parent::asXML($filename, $human);
 }
Exemplo n.º 9
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";
#open the image.svg
$image = SVGDocument::getInstance('resource/image.svg');
#converter to xml text
$xml = $image->asXML();
#execute the replace, you can use reg exp if you need
$xml = str_replace('This is my stick boy!', 'Changed text!', $xml);
#construct a new xml based in new xml content
$svg = new SVGDocument($xml);
#make the output
$svg->output();
Exemplo n.º 10
0
 *   (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());
    public function createImageFromSvg()
    {
        if (!isset($this->request->post['order_id']) || !isset($this->request->post['item_id']) || !isset($this->request->post['svg']) || !isset($this->request->post['title'])) {
            exit;
        }
        require_once DIR_SYSTEM . 'library/svglib/svglib.php';
        $order_id = trim($this->request->post['order_id']);
        $item_id = trim($this->request->post['item_id']);
        $svg = stripslashes(trim($this->request->post['svg']));
        $width = trim($this->request->post['width']);
        $height = trim($this->request->post['height']);
        $title = trim($this->request->post['title']);
        //create fancy product orders directory
        if (!file_exists(DIR_IMAGE)) {
            mkdir(DIR_IMAGE);
        }
        //create uploads dir
        $images_dir = DIR_IMAGE . 'design_products_orders/';
        if (!file_exists($images_dir)) {
            mkdir($images_dir);
        }
        $images_dir = DIR_IMAGE . 'design_products_orders/images/';
        if (!file_exists($images_dir)) {
            mkdir($images_dir);
        }
        //create order dir
        $order_dir = $images_dir . $order_id . '/';
        if (!file_exists($order_dir)) {
            mkdir($order_dir);
        }
        //create item dir
        $item_dir = $order_dir . $item_id . '/';
        if (!file_exists($item_dir)) {
            mkdir($item_dir);
        }
        $image_path = $item_dir . $title . '.svg';
        $image_exist = file_exists($image_path);
        header('Content-Type: application/json');
        try {
            $svg = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
			<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="' . $width . '" height="' . $height . '" xml:space="preserve">' . $svg . '</svg>';
            $svg_doc = new SVGDocument(html_entity_decode($svg, ENT_QUOTES, 'UTF-8'));
            $svg_doc->asXML($image_path);
            $image_url = str_replace(DIR_IMAGE, HTTP_CATALOG . 'image/', $image_path);
            $this->response->setOutput(json_encode(array('code' => $image_exist ? 302 : 201, 'url' => $image_url, 'title' => $title)));
        } catch (Exception $e) {
            $this->response->setOutput(json_encode(array('code' => 500)));
        }
    }
Exemplo n.º 12
0
 /**
  * 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;
         }
     }
 }