class_mcCairoSvg.inc.php 2.98 KB
<?php

class mcCairoSvg  {
	
	public static function inkscapeSvgToPdf($param_input_filename, array $param_outputfile=null, array $param_quality =null,$param_keep_svg=false) {
		if($param_keep_svg !==TRUE){
			$normalsvg_filename =mcInkscape::inkscapeSvgToNormalSvg($param_input_filename);
//			$normalsvg_filename=$param_input_filename;
		}else{
			$normalsvg_filename=$param_input_filename;
		}
		
		mcFile::manipulateOutputfileArray($param_outputfile, $param_input_filename);
		return mcCairoSvg::svgToPdf($normalsvg_filename, $param_outputfile, $param_quality);
	}
	
	public static function inkscapeSvgToPng($param_input_filename, array $param_outputfile=null, array $param_quality =null) {
		$normalsvg_filename =mcInkscape::inkscapeSvgToNormalSvg($param_input_filename);
		mcFile::manipulateOutputfileArray($param_outputfile, $param_input_filename);
		return mcCairoSvg::svgToPng($normalsvg_filename, $param_outputfile, $param_quality);
	}
	
	public static function inkscapeSvgToPs($param_input_filename, array $param_outputfile=null, array $param_quality =null) {
		$normalsvg_filename =mcInkscape::inkscapeSvgToNormalSvg($param_input_filename);
		mcFile::manipulateOutputfileArray($param_outputfile, $param_input_filename);
		return mcCairoSvg::svgToPs($normalsvg_filename, $param_outputfile, $param_quality);
	}	
	
	/**
	 * 
	 * @param string $param_svgFileString
	 */
	public static function svgToPdf($param_input_filename, array $param_outputfile=null, array $param_quality =null) {
		return mcCairoSvg::doCairosvg('pdf', $param_input_filename, $param_outputfile, $param_quality);
	}

	public static function svgToPng($param_input_filename, array $param_outputfile=null, array $param_quality =null) {
		return mcCairoSvg::doCairosvg('png', $param_input_filename, $param_outputfile, $param_quality);
	}

	public static function svgToPs($param_input_filename, array $param_outputfile=null, array $param_quality =null) {
		return mcCairoSvg::doCairosvg('ps', $param_input_filename, $param_outputfile, $param_quality);
	}	
	
	private static function doCairosvg($param_format, $param_input_filename, array $param_outputfile=null, array $param_quality =null) {
		
		mcFile::manipulateOutputfileArray($param_outputfile,$param_input_filename);

		if(!$param_outputfile['filename']) {
			$param_outputfile['filenameextension'] = '.'.$param_format;
			$out_pdf = mcFile::createTmpFile($param_outputfile);
		} else {
			$out_pdf = $param_outputfile['filename'];
		}
		
		if(!$param_quality['DPI']) {
			$param_quality['DPI'] = 30;
		}		
		
		$order = $ausgabe = $return_var = null;
		$order = "/var/www/Magento/CairoSVG/cairosvg.sh '".$param_input_filename."' '".$out_pdf."' '".$param_format."' '".$param_quality['DPI']."' ";
//		D::ulli('$'.$order);
//		$shell_exec = shell_exec($order);	
//		$shell_exec = exec($order, $ausgabe, $return_var);	
		$shell_exec = mcBash::exec($order, $ausgabe, $return_var);
//		D::show(array('$shell_exec' => $shell_exec, '$ausgabe'=>$ausgabe, '$return_var' => $return_var), $order);

		return $out_pdf;		
	}
	

}
?>