1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* martin image show |
4
|
|
|
* @copyright 1997-2010 The Lap Group |
5
|
|
|
* @author Martin <[email protected]> |
6
|
|
|
* @created time :2010-06-18 11:34:10 |
7
|
|
|
* */ |
8
|
|
|
$id = isset($_GET['id']) ? trim($_GET['id']) : null; |
9
|
|
|
|
10
|
|
|
$FileType = strtolower(substr(strrchr($id, "."), 1)); |
11
|
|
|
|
12
|
|
|
$full = './images/hotelicon/' . $id; |
13
|
|
|
$full = file_exists($full) ? $full : './images/hotel/' . $id; |
14
|
|
|
|
15
|
|
|
if (is_null($id)) { |
16
|
|
|
throw new Exception('Error : Image Id Is Not Null.'); |
17
|
|
|
} elseif (!file_exists($full)) { |
18
|
|
|
throw new Exception('Error : No Such File.'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
//简化 |
22
|
|
|
$handler = fopen($full, 'rb'); |
23
|
|
|
header("Content-type: image/png"); |
24
|
|
|
header("Content-Length: " . filesize($full)); |
25
|
|
|
fpassthru($handler); |
26
|
|
|
fclose($handler); |
27
|
|
|
exit; |
28
|
|
|
|
29
|
|
View Code Duplication |
switch ($FileType) { |
|
|
|
|
30
|
|
|
case "jpg": |
31
|
|
|
$img = imagecreatefromjpeg($full); |
32
|
|
|
break; |
33
|
|
|
case "png": |
34
|
|
|
$img = imagecreatefrompng($full); |
35
|
|
|
break; |
36
|
|
|
case "gif": |
37
|
|
|
$img = imagecreatefromgif($full); |
38
|
|
|
break; |
39
|
|
|
case "bmp": |
40
|
|
|
$img = imagecreatefromwbmp($full); |
41
|
|
|
break; |
42
|
|
|
default: |
43
|
|
|
throw new Exception("ERROR:image type error " . $full); |
44
|
|
|
exit(0); |
45
|
|
|
break; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$width = imageSX($img); |
49
|
|
|
$height = imageSY($img); |
50
|
|
|
|
51
|
|
|
$new_img = ImageCreateTrueColor($width, $height); |
52
|
|
View Code Duplication |
if (!@imagefilledrectangle($new_img, 0, 0, $target_width - 1, $target_height - 1, 0)) { // Fill the image black |
|
|
|
|
53
|
|
|
echo _AM_MARTIN_ERROR_COULD_NOT_FILL_NEW_IMAGE; |
54
|
|
|
exit(0); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
View Code Duplication |
if (!@imagecopyresampled($new_img, $img, 0, 0, 0, 0, $width, $height, $width, $height)) { |
|
|
|
|
58
|
|
|
echo _AM_MARTIN_ERROR_COULD_NOT_RESIZE_IMAGE; |
59
|
|
|
exit(0); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
ob_start(); |
63
|
|
|
// Get the image and create a thumbnail |
64
|
|
View Code Duplication |
switch ($FileType) { |
|
|
|
|
65
|
|
|
case "jpg": |
66
|
|
|
imagejpeg($new_img); |
67
|
|
|
break; |
68
|
|
|
case "png": |
69
|
|
|
imagepng($new_img); |
70
|
|
|
break; |
71
|
|
|
case "gif": |
72
|
|
|
imagegif($new_img); |
73
|
|
|
break; |
74
|
|
|
case "bmp": |
75
|
|
|
imagewbmp($new_img); |
76
|
|
|
break; |
77
|
|
|
} |
78
|
|
|
$imagevariable = ob_get_contents(); |
79
|
|
|
ob_end_clean(); |
80
|
|
|
|
81
|
|
|
header("Content-type: image/jpeg"); |
82
|
|
|
header("Content-Length: " . strlen($imagevariable)); |
83
|
|
|
echo $imagevariable; |
84
|
|
|
exit(0); |
85
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.