/**
 *  Gets Export data from FCExporter - main module and build the export binary/objct.
 *  @param	$stream 	(string) export image data in FusionCharts compressed format
 *      	$meta		{array)	Image meta data in keys "width", "heigth" and "bgColor"
 *              $exportParams   {array} Export related parameters
 *  @return 			image object/binary
 */
function exportProcessor($stream, $meta, $exportParams)
{
    // get mime type list parsing MIMETYPES constant declared in Export Resource PHP file
    $ext = strtolower($exportParams["exportformat"]);
    $mimeList = bang(@MIMETYPES);
    $mimeType = $mimeList[$ext];
    // prepare variables
    if (get_magic_quotes_gpc()) {
        $stream = stripslashes($stream);
    }
    // create a new export data
    $tempFileName = md5(rand());
    $tempOutputFile = TEMP_PATH . "{$tempFileName}.{$ext}";
    $tempInputSVGFile = TEMP_PATH . "{$tempFileName}.svg";
    if ($ext != 'svg') {
        // width format for batik
        $width = @$meta['width'];
        if ($width) {
            $width = "-w {$width}";
        }
        //batik bg color format
        $bg = @$meta['bgColor'];
        if ($bg) {
            $bg = "-bg 255." . hex2rgb($bg, ".");
        }
        // generate the temporary file
        if (!file_put_contents($tempInputSVGFile, $stream)) {
            die("Couldn't create temporary file. Check that the directory permissions for\r\n\t\t\tthe " . TEMP_PATH . " directory are set to 777.");
        }
        // do the conversion
        $command = "java -jar " . BATIK_PATH . " -m {$mimeType} {$width} {$bg} {$tempInputSVGFile}";
        $output = shell_exec($command);
        // catch error
        if (!is_file($tempOutputFile) || filesize($tempOutputFile) < 10) {
            $return_binary = "{$output}";
            raise_error($output, true);
        } else {
            $return_binary = file_get_contents($tempOutputFile);
        }
        // delete temp files
        if (file_exists($tempInputSVGFile)) {
            unlink($tempInputSVGFile);
        }
        if (file_exists($tempOutputFile)) {
            unlink($tempOutputFile);
        }
        // SVG can be streamed back directly
    } else {
        if ($ext == 'svg') {
            $return_binary = $stream;
        } else {
            raise_error("Invalid Export Format.", true);
        }
    }
    // return export ready binary data
    return @$return_binary;
}
Beispiel #2
0
/**
 *  gets file extension checking the export type.
 *  @param  $exportType     (string) export format
 *  @return file extension as string
 */
function getExtension($exportType)
{
    // get an associative array of [type=> extension]
    // from EXTENSIONS constant defined in Export Resource PHP file
    $extensionList = bang(@EXTENSIONS);
    $exportType = strtolower($exportType);
    // if extension type is present in $extensionList return it, otherwise return the type
    return @$extensionList[$exportType] ? $extensionList[$exportType] : $exportType;
}
/**
 *  Gets Export data from FCExporter - main module and build the export binary/objct.
 *  @param	$stream 	(string) export image data in FusionCharts compressed format
 *      	$meta		{array)	Image meta data in keys "width", "heigth" and "bgColor"
 *              $exportParams   {array} Export related parameters
 *  @return 			image object/binary
 */
function exportProcessor($stream, $meta, $exportParams)
{
    // get mime type list parsing MIMETYPES constant declared in Export Resource PHP file
    $ext = strtolower($exportParams["exportformat"]);
    $ext2 = '';
    $mimeList = bang(@MIMETYPES);
    $mimeType = $mimeList[$ext];
    // prepare variables
    if (get_magic_quotes_gpc()) {
        $stream = stripslashes($stream);
    }
    // create a new export data
    $tempFileName = md5(rand());
    if ('jpeg' == $ext || 'jpg' == $ext) {
        $ext = 'png';
        $ext2 = 'jpg';
    }
    $tempInputSVGFile = realpath(TEMP_PATH) . "/{$tempFileName}.svg";
    $tempOutputFile = realpath(TEMP_PATH) . "/{$tempFileName}.{$ext}";
    $tempOutputJpgFile = realpath(TEMP_PATH) . "/{$tempFileName}.jpg";
    $tempOutputPngFile = realpath(TEMP_PATH) . "/{$tempFileName}.png";
    if ($ext != 'svg') {
        // width format for batik
        $width = @$meta['width'];
        $height = @$meta['height'];
        $size = '';
        if (!empty($width) && !empty($height)) {
            $size = "-w {$width} -h {$height}";
        }
        // override the size in case of pdf output
        if ('pdf' == $ext) {
            $size = '';
        }
        //batik bg color format
        $bg = @$meta['bgColor'];
        if ($bg) {
            $bg = " --export-background=" . $bg;
        }
        // generate the temporary file
        if (!file_put_contents($tempInputSVGFile, $stream)) {
            die("Couldn't create temporary file. Check that the directory permissions for\n\t\t\tthe " . TEMP_PATH . " directory are set to 777.");
        }
        // do the conversion
        $command = INKSCAPE_PATH . "{$bg} --without-gui {$tempInputSVGFile} --export-{$ext} {$tempOutputFile} {$size}";
        $output = shell_exec($command);
        if ('jpg' == $ext2) {
            $comandJpg = CONVERT_PATH . " -quality 100 {$tempOutputFile} {$tempOutputJpgFile}";
            $tempOutputFile = $tempOutputJpgFile;
            $output .= shell_exec($comandJpg);
        }
        // catch error
        if (!is_file($tempOutputFile) || filesize($tempOutputFile) < 10) {
            $return_binary = $output;
            raise_error($output, true);
        } else {
            $return_binary = file_get_contents($tempOutputFile);
        }
        // delete temp files
        if (file_exists($tempInputSVGFile)) {
            unlink($tempInputSVGFile);
        }
        if (file_exists($tempOutputFile)) {
            unlink($tempOutputFile);
        }
        if (file_exists($tempOutputPngFile)) {
            unlink($tempOutputPngFile);
        }
        // SVG can be streamed back directly
    } else {
        if ($ext == 'svg') {
            $return_binary = $stream;
        } else {
            raise_error("Invalid Export Format.", true);
        }
    }
    // return export ready binary data
    return @$return_binary;
}