Commit b3967bc5 by sn

Files .. inkscape cairo manipulationen

1 parent 10f507e3
<?php <?php
class mcCairoSvg { 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 * @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) { mcFile::manipulateOutputfileArray($param_outputfile,$param_input_filename);
// $param_out_pdf = tempnam("/tmp", "mcInkscape_");
// $tmp_png = $param_out_pdf.'.pdf'; if(!$param_outputfile['filename']) {
// mcFile::rename($param_out_pdf, $tmp_png); $param_outputfile['filenameextension'] = '.'.$param_format;
// $param_out_pdf = $tmp_png; $out_pdf = mcFile::createTmpFile($param_outputfile);
$param_out_pdf = mcFile::createTmpFile('.pdf', 'mcCairo_', $param_out_dir); } else {
$out_pdf = $param_outputfile['filename'];
} }
// $inkscape_order = "cairosvg.sh $param_in_svg $param_out_pdf"; if(!$param_quality['DPI']) {
$inkscape_order = "python /home/dev/CairoSVG//cairosvg.py '".$param_in_svg."' -d 90 --output='".$param_out_pdf."' "; $param_quality['DPI'] = 90;
}
// $shell_exec = shell_exec($inkscape_order);
$shell_exec = exec($inkscape_order, $ausgabe, $return_var); $order = $ausgabe = $return_var = null;
D::show(array('$shell_exec' => $shell_exec, '$ausgabe'=>$ausgabe, '$return_var' => $return_var), $inkscape_order); $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 { ...@@ -89,20 +89,61 @@ class mcFile {
} }
/** /**
* erstellt eine temporäre Datei, für weitere Dateimanipulatioin
* *
* @param string $param_filepostfix exampe: .pdf, .txt, .csv * @param array $param_outputfile @see mcFile::manipulateOutputfileArray($param_outputfile)
* @param string $param_prefix
* @return string * @return string
*/ */
public static function createTmpFile($param_filepostfix='.tmp', $param_prefix='tmp_', $param_dir='/tmp/') { public static function createTmpFile(array $param_outputfile=null) {
$param_file = tempnam($param_dir, $param_prefix); if(is_null($param_outputfile)) {
if($param_filepostfix) { $param_outputfile = array();
$tmp_filename = $param_file.$param_filepostfix; }
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 // @todo tempfile auch noch mal überprüfen, das es nicht existiert
mcFile::rename($param_file, $tmp_filename); mcFile::rename($param_file, $tmp_filename);
} }
return $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 { ...@@ -6,38 +6,57 @@ class mcInkscape {
* *
* @param string $param_svgFileString * @param string $param_svgFileString
*/ */
public static function svgToPng($param_in_svg, $param_out_png=false) { public static function svgToPng($param_input_filename, array $param_outputfile=null, array $param_quality =null) {
mcFile::manipulateOutputfileArray($param_outputfile, $param_input_filename);
if($param_out_png === false) { if(!$param_outputfile['filename']) {
$param_out_png = tempnam("/tmp", "mcInkscape_"); if(!$param_outputfile['filenameextension']) {
$tmp_png = $param_out_png.'.png'; $param_outputfile['filenameextension'] = '.png';
mcFile::rename($param_out_png, $tmp_png); }
$param_out_png = $tmp_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"; $order = "inkscape $param_input_filename --export-dpi=".$param_quality['dpi']." -e $outfile";
$shell_exec = shell_exec($inkscape_order); D::ulli('$'.$order);
$shell_exec = shell_exec($order);
return $param_out_png; return $outfile;
} }
/** /**
* *
* @param string $param_svgFileString * @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) { if(!$param_quality['DPI']) {
$param_out_pdf = tempnam("/tmp", "mcInkscape_"); $param_quality['DPI'] = 90;
$tmp_png = $param_out_pdf.'.pdf';
mcFile::rename($param_out_pdf, $tmp_png);
$param_out_pdf = $tmp_png;
} }
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 { ...@@ -48,16 +67,23 @@ class mcInkscape {
} }
public static function inkscapeSvgToNormalSvg($param_in_svg, $param_out_dir=false, $param_out_filename=false, $param_filenamePrefix='normalSvg_') { public static function inkscapeSvgToNormalSvg($param_input_filename, array $param_outputfile=null) {
if($param_out_filename === false) { mcFile::manipulateOutputfileArray($param_outputfile, $param_input_filename);
$param_out_filename = mcFile::createTmpFile('.svg', $param_filenamePrefix, $param_out_dir); 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); $shell_exec = shell_exec($inkscape_order);
D::show($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!