Commit b3967bc5 by sn

Files .. inkscape cairo manipulationen

1 parent 10f507e3
<?php
class mcCairoSvg {
public static function inkscapeSvgToPdf($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, $param_quality);
return mcCairoSvg::svgToPdf($normalsvg_filename, $param_outputfile);
}
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, $param_quality);
return mcCairoSvg::svgToPng($normalsvg_filename, $param_outputfile);
}
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, $param_quality);
return mcCairoSvg::svgToPs($normalsvg_filename, $param_outputfile);
}
/**
*
* @param string $param_svgFileString
*/
public static function svgToPdf($param_in_svg, $param_out_dir=false, $param_out_pdf=false) {
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) {
if($param_out_pdf === false) {
// $param_out_pdf = tempnam("/tmp", "mcInkscape_");
// $tmp_png = $param_out_pdf.'.pdf';
// mcFile::rename($param_out_pdf, $tmp_png);
// $param_out_pdf = $tmp_png;
$param_out_pdf = mcFile::createTmpFile('.pdf', 'mcCairo_', $param_out_dir);
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'];
}
// $inkscape_order = "cairosvg.sh $param_in_svg $param_out_pdf";
$inkscape_order = "python /home/dev/CairoSVG//cairosvg.py '".$param_in_svg."' -d 90 --output='".$param_out_pdf."' ";
// $shell_exec = shell_exec($inkscape_order);
$shell_exec = exec($inkscape_order, $ausgabe, $return_var);
D::show(array('$shell_exec' => $shell_exec, '$ausgabe'=>$ausgabe, '$return_var' => $return_var), $inkscape_order);
if(!$param_quality['DPI']) {
$param_quality['DPI'] = 90;
}
$order = $ausgabe = $return_var = null;
$order = "/home/dev/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);
D::show(array('$shell_exec' => $shell_exec, '$ausgabe'=>$ausgabe, '$return_var' => $return_var), $order);
return $param_out_pdf;
return $out_pdf;
}
public static function inkscapeSvgToPdf($param_in_svg, $param_out_dir=false, $param_out_pdf=false) {
$normalsvg_filename =mcInkscape::inkscapeSvgToNormalSvg($param_in_svg);
return mcCairoSvg::svgToPdf($normalsvg_filename, $param_out_dir, $param_out_pdf);
}
}
?>
?>
\ No newline at end of file
......@@ -89,20 +89,61 @@ class mcFile {
}
/**
* erstellt eine temporäre Datei, für weitere Dateimanipulatioin
*
* @param string $param_filepostfix exampe: .pdf, .txt, .csv
* @param string $param_prefix
* @param array $param_outputfile @see mcFile::manipulateOutputfileArray($param_outputfile)
* @return string
*/
public static function createTmpFile($param_filepostfix='.tmp', $param_prefix='tmp_', $param_dir='/tmp/') {
$param_file = tempnam($param_dir, $param_prefix);
if($param_filepostfix) {
$tmp_filename = $param_file.$param_filepostfix;
public static function createTmpFile(array $param_outputfile=null) {
if(is_null($param_outputfile)) {
$param_outputfile = array();
}
mcFile::manipulateOutputfileArray($param_outputfile);
$param_file = tempnam($param_outputfile['dirname'], $param_outputfile['prefix']);
if($param_outputfile['filenameextension']) {
$tmp_filename = $param_file.$param_outputfile['filenameextension'];
// @todo tempfile auch noch mal überprüfen, das es nicht existiert
mcFile::rename($param_file, $tmp_filename);
}
return $tmp_filename;
}
/**
* manipuliert $param_outputfile so das Informationen für die zuerstellende Datei
* für Dateimanipulationen vorliegen
*
* @todo es könnte überprüft werden ob $param_outputfile['dirname'] schreibbar ist
* @todo es könnte überprüft werden ob $param_outputfile['filename'] schreibbar ist
* @todo filepath könnte alle anderen Werte generieren
*
* @param array $param_outputfile - array('dirname'=>,'prefix'=>,'filename'=>,'filenameextension'=>, )
* @param type $param_filepath - generiert bis jetzt nur dirname
*/
public static function manipulateOutputfileArray(array &$param_outputfile, $param_filepath=null) {
if(!array_key_exists('dirname', $param_outputfile)) {
if(!is_null($param_filepath)) {
$path_parts = pathinfo($param_filepath);
$param_outputfile['dirname'] = $path_parts['dirname'].'/';
} else {
$param_outputfile['dirname'] = '/tmp/';
}
}
if(!array_key_exists('prefix', $param_outputfile)) {
$param_outputfile['prefix'] = '';
}
if(!array_key_exists('filename', $param_outputfile)) {
$param_outputfile['filename'] = '';
}
if(!array_key_exists('filenameextension', $param_outputfile)) {
$param_outputfile['filenameextension'] = '';
}
}
}
?>
......@@ -6,38 +6,57 @@ class mcInkscape {
*
* @param string $param_svgFileString
*/
public static function svgToPng($param_in_svg, $param_out_png=false) {
if($param_out_png === false) {
$param_out_png = tempnam("/tmp", "mcInkscape_");
$tmp_png = $param_out_png.'.png';
mcFile::rename($param_out_png, $tmp_png);
$param_out_png = $tmp_png;
public static function svgToPng($param_input_filename, array $param_outputfile=null, array $param_quality =null) {
mcFile::manipulateOutputfileArray($param_outputfile, $param_input_filename);
if(!$param_outputfile['filename']) {
if(!$param_outputfile['filenameextension']) {
$param_outputfile['filenameextension'] = '.png';
}
$outfile = mcFile::createTmpFile($param_outputfile);
} else {
$outfile = $param_outputfile['filename'];
}
if(!$param_quality['dpi']) {
$param_quality['dpi'] = 90;
}
$inkscape_order = "inkscape $param_in_svg -e $param_out_png";
$shell_exec = shell_exec($inkscape_order);
$order = "inkscape $param_input_filename --export-dpi=".$param_quality['dpi']." -e $outfile";
D::ulli('$'.$order);
$shell_exec = shell_exec($order);
return $param_out_png;
return $outfile;
}
/**
*
* @param string $param_svgFileString
*/
public static function svgToPdf($param_in_svg, $param_out_pdf=false) {
public static function svgToPdf($param_input_filename, array $param_outputfile=null, array $param_quality =null) {
mcFile::manipulateOutputfileArray($param_outputfile, $param_input_filename);
if(!$param_outputfile['filename']) {
if(!$param_outputfile['filenameextension']) {
$param_outputfile['filenameextension'] = '.pdf';
}
$outfile = mcFile::createTmpFile($param_outputfile);
} else {
$outfile = $param_outputfile['filename'];
}
if($param_out_pdf === false) {
$param_out_pdf = tempnam("/tmp", "mcInkscape_");
$tmp_png = $param_out_pdf.'.pdf';
mcFile::rename($param_out_pdf, $tmp_png);
$param_out_pdf = $tmp_png;
if(!$param_quality['DPI']) {
$param_quality['DPI'] = 90;
}
if(!$param_quality['PDF_VERSION']) {
$param_quality['PDF_VERSION'] = 1.4;
}
$inkscape_order = "inkscape $param_in_svg -A $param_out_pdf";
$shell_exec = shell_exec($inkscape_order);
$order = "inkscape $param_input_filename --export-dpi=".$param_quality['dpi']." --export-pdf=$outfile";
D::ulli('$'.$order);
$shell_exec = shell_exec($order);
return $param_out_pdf;
return $outfile;
}
......@@ -48,16 +67,23 @@ class mcInkscape {
}
public static function inkscapeSvgToNormalSvg($param_in_svg, $param_out_dir=false, $param_out_filename=false, $param_filenamePrefix='normalSvg_') {
if($param_out_filename === false) {
$param_out_filename = mcFile::createTmpFile('.svg', $param_filenamePrefix, $param_out_dir);
public static function inkscapeSvgToNormalSvg($param_input_filename, array $param_outputfile=null) {
mcFile::manipulateOutputfileArray($param_outputfile, $param_input_filename);
if(!$param_outputfile['filename']) {
if(!$param_outputfile['filenameextension']) {
$param_outputfile['filenameextension'] = '.svg';
}
$outfile = mcFile::createTmpFile($param_outputfile);
} else {
$outfile = $param_outputfile['filename'];
}
$inkscape_order = "inkscape -T $param_in_svg -l $param_out_filename";
$inkscape_order = "inkscape -T ".$param_input_filename." -l ".$outfile." ";
$shell_exec = shell_exec($inkscape_order);
D::show($shell_exec, $inkscape_order);
return $param_out_filename;
return $outfile;
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!