Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
ncphp
/
mcClasses
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b3967bc5
authored
Dec 21, 2013
by
sn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Files .. inkscape cairo manipulationen
1 parent
10f507e3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
144 additions
and
45 deletions
file/class_mcCairoSvg.inc.php
file/class_mcFile.inc.php
file/class_mcInkscape.inc.php
file/class_mcCairoSvg.inc.php
View file @
b3967bc
<?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
);
}
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
);
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
);
}
// $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
.
"' "
;
private
static
function
doCairosvg
(
$param_format
,
$param_input_filename
,
array
$param_outputfile
=
null
,
array
$param_quality
=
null
)
{
// $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
);
mcFile
::
manipulateOutputfileArray
(
$param_outputfile
,
$param_input_filename
);
return
$param_out_pdf
;
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'
]
=
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
);
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
);
return
$out_pdf
;
}
}
?>
\ No newline at end of file
file/class_mcFile.inc.php
View file @
b3967bc
...
...
@@ -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'
]
=
''
;
}
}
}
?>
file/class_mcInkscape.inc.php
View file @
b3967bc
...
...
@@ -6,38 +6,57 @@ class mcInkscape {
*
* @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_outputfile
[
'filename'
])
{
if
(
!
$param_outputfile
[
'filenameextension'
])
{
$param_outputfile
[
'filenameextension'
]
=
'.png'
;
}
$outfile
=
mcFile
::
createTmpFile
(
$param_outputfile
);
}
else
{
$outfile
=
$param_outputfile
[
'filename'
];
}
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
;
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'
;
}
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
;
$outfile
=
mcFile
::
createTmpFile
(
$param_outputfile
);
}
else
{
$outfile
=
$param_outputfile
[
'filename'
];
}
$inkscape_order
=
"inkscape
$param_in_svg
-A
$param_out_pdf
"
;
$shell_exec
=
shell_exec
(
$inkscape_order
);
if
(
!
$param_quality
[
'DPI'
])
{
$param_quality
[
'DPI'
]
=
90
;
}
if
(
!
$param_quality
[
'PDF_VERSION'
])
{
$param_quality
[
'PDF_VERSION'
]
=
1.4
;
}
$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_filenam
e
;
return
$
outfil
e
;
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment