class_mcInkscape.inc.php
3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
class mcInkscape {
/**
*
* @param string $param_svgFileString
*/
public static function svgToPng($param_input_filename, array $param_outputfile = null, array $param_quality = null) {
self::replaceInSvGFile($param_input_filename);
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;
}
$order = "inkscape $param_input_filename --export-dpi=" . $param_quality['dpi'] . " -e $outfile";
// D::ulli('$'.$order);
// $shell_exec = shell_exec($order);
$shell_exec = mcBash::shell_exec($order);
return $outfile;
}
/**
*
* @param string $param_svgFileString
*/
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_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);
$shell_exec = mcBash::shell_exec($order);
return $outfile;
}
public static function svgToJpg($param_in_svg, $param_out_jpg = false, $param_quality = 100) {
$new_png = mcInkscape::svgToPng($param_in_svg);
// D::li('1.1 $new_png: '.$new_png);
return mcImage::pngToJpg($new_png, $param_out_jpg, $param_quality);
}
public static function inkscapeSvgToNormalSvg($param_input_filename, array $param_outputfile = null) {
self::replaceInSvGFile($param_input_filename);
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_input_filename . " -l " . $outfile . " ";
$shell_exec = mcBash::shell_exec($inkscape_order);
return $outfile;
}
public function replaceInSvGFile($param_input_filename) {
$replacearray = array(
'flowpara' => 'flowPara',
'flowspan' => 'flowSpan',
);//Mage::helper('anc_printconfigproduct/constant')->get('ancTransTagsCaseInkscape');
$str = implode("\n", file($param_input_filename));
$fp = fopen($param_input_filename, 'w');
foreach ($replacearray as $key => $value) {
$str = str_replace($key, $value, $str);
}
fwrite($fp, $str, strlen($str));
}
}
?>