| 1 |
lars |
1 |
<?php
|
|
|
2 |
// $Header: /cvsroot/html2ps/utils_graphic.php,v 1.9 2007/01/24 18:56:10 Konstantin Exp $
|
|
|
3 |
|
|
|
4 |
function do_image_open($filename, &$type) {
|
|
|
5 |
// Gracefully process missing GD extension
|
|
|
6 |
if (!extension_loaded('gd')) {
|
|
|
7 |
return null;
|
|
|
8 |
};
|
|
|
9 |
|
|
|
10 |
// Disable interlacing for the generated images, as we do not need progressive images
|
|
|
11 |
// if PDF files (futhermore, FPDF does not support such images)
|
|
|
12 |
$image = do_image_open_wrapped($filename, $type);
|
|
|
13 |
if (!is_resource($image)) { return null; };
|
|
|
14 |
|
|
|
15 |
if (!is_null($image)) {
|
|
|
16 |
imageinterlace($image, 0);
|
|
|
17 |
};
|
|
|
18 |
|
|
|
19 |
return $image;
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
function do_image_open_wrapped($filename, &$type) {
|
|
|
23 |
// FIXME: it will definitely cause problems;
|
|
|
24 |
global $g_config;
|
|
|
25 |
if (!$g_config['renderimages']) {
|
|
|
26 |
return null;
|
|
|
27 |
};
|
|
|
28 |
|
|
|
29 |
// get the information about the image
|
|
|
30 |
if (!$data = @getimagesize($filename)) { return null; };
|
|
|
31 |
switch ($data[2]) {
|
|
|
32 |
case 1: // GIF
|
|
|
33 |
$type = 'image/png';
|
|
|
34 |
// Handle lack of GIF support in older versions of PHP
|
|
|
35 |
if (function_exists('imagecreatefromgif')) {
|
|
|
36 |
return @imagecreatefromgif($filename);
|
|
|
37 |
} else {
|
|
|
38 |
return null;
|
|
|
39 |
};
|
|
|
40 |
case 2: // JPG
|
|
|
41 |
$type = 'image/jpeg';
|
|
|
42 |
return @imagecreatefromjpeg($filename);
|
|
|
43 |
case 3: // PNG
|
|
|
44 |
$type = 'image/png';
|
|
|
45 |
$image = imagecreatefrompng($filename);
|
|
|
46 |
// imagealphablending($image, false);
|
|
|
47 |
// imagesavealpha($image, true);
|
|
|
48 |
return $image;
|
|
|
49 |
case 15: // WBMP
|
|
|
50 |
$type = 'image/png';
|
|
|
51 |
return @imagecreatefromwbmp($filename);
|
|
|
52 |
};
|
|
|
53 |
return null;
|
|
|
54 |
};
|
|
|
55 |
?>
|