class_mcImage.inc.php
1.03 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
<?php
/**
* @copyright (c) 2014, netz.coop eG
*/
class mcImage {
/**
*
* @param string $param_svgFileString
*/
public static function pngToJpg($param_in_png, $param_out_jpg=false, $param_quality=100) {
if($param_out_jpg === false) {
$param_out_jpg = tempnam("/tmp", "mcImage_");
$tmp_jpg = $param_out_jpg.'.jpg';
mcFile::rename($param_out_jpg, $tmp_jpg);
$param_out_jpg = $tmp_jpg;
}
$shell_exec = mcImage::GD_pngToJpg($param_in_png, $param_out_jpg, $param_quality);
// D::show($shell_exec);
if($shell_exec) {
return $param_out_jpg;
} else {
return false;
}
}
/**
*
* GD library
*
* @param type $originalFile
* @param type $outputFile
* @param type $quality - Quality is a number between 0 (best compression) and 100 (best quality)
*/
protected static function GD_pngToJpg($originalFile, $outputFile, $quality) {
$image = imagecreatefrompng($originalFile);
$return = imagejpeg($image, $outputFile, $quality);
imagedestroy($image);
return $return;
}
}
?>