1
|
|
|
<?php |
2
|
|
|
$img_id = $_GET['id']; |
3
|
|
|
|
4
|
|
|
$hotel_icon = './images/hotelicon/' . $img_id; |
5
|
|
|
|
6
|
|
|
$hotel_icon = file_exists($hotel_icon) ? $hotel_icon : './images/hotel/' . $img_id; |
7
|
|
|
|
8
|
|
|
if (!file_exists($hotel_icon)) { |
9
|
|
|
throw Exception($hotel_icon . ' Not Found.'); |
10
|
|
|
exit(0); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
$FileType = strtolower(substr(strrchr($hotel_icon, "."), 1)); |
14
|
|
|
|
15
|
|
|
$img_t = isset($_GET['t']) ? trim($_GET['t']) : null; |
16
|
|
|
|
17
|
|
|
$target_width = isset($_GET['w']) ? (int)($_GET['w']) : 100; |
18
|
|
|
$target_height = isset($_GET['h']) ? (int)($_GET['h']) : 100; |
19
|
|
|
|
20
|
|
View Code Duplication |
switch ($FileType) { |
|
|
|
|
21
|
|
|
case "jpg": |
22
|
|
|
$img = imagecreatefromjpeg($hotel_icon); |
23
|
|
|
break; |
24
|
|
|
case "png": |
25
|
|
|
$img = imagecreatefrompng($hotel_icon); |
26
|
|
|
break; |
27
|
|
|
case "gif": |
28
|
|
|
$img = imagecreatefromgif($hotel_icon); |
29
|
|
|
break; |
30
|
|
|
case "bmp": |
31
|
|
|
$img = imagecreatefromwbmp($hotel_icon); |
32
|
|
|
break; |
33
|
|
|
default: |
34
|
|
|
echo "ERROR:image type error " . $hotel_icon; |
35
|
|
|
exit(0); |
36
|
|
|
break; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$width = imageSX($img); |
40
|
|
|
$height = imageSY($img); |
41
|
|
|
//var_dump($height);exit; |
42
|
|
|
|
43
|
|
|
$target_ratio = $target_width / $target_height; |
44
|
|
|
$img_ratio = $width / $height; |
45
|
|
|
|
46
|
|
View Code Duplication |
if ($target_ratio > $img_ratio) { |
|
|
|
|
47
|
|
|
$new_height = $target_height; |
48
|
|
|
$new_width = $img_ratio * $target_height; |
49
|
|
|
} else { |
50
|
|
|
$new_height = $target_width / $img_ratio; |
51
|
|
|
$new_width = $target_width; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if ($new_height > $target_height) { |
55
|
|
|
$new_height = $target_height; |
56
|
|
|
} |
57
|
|
|
if ($new_width > $target_width) { |
58
|
|
|
$new_height = $target_width; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$new_img = ImageCreateTrueColor($target_width, $target_height); |
62
|
|
View Code Duplication |
if (!@imagefilledrectangle($new_img, 0, 0, $target_width - 1, $target_height - 1, 0)) { |
|
|
|
|
63
|
|
|
// Fill the image black |
64
|
|
|
echo _AM_MARTIN_ERROR_COULD_NOT_FILL_NEW_IMAGE; |
65
|
|
|
exit(0); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
//if (!@imagecopyresampled($new_img, $img, ($target_width-$new_width)/2, ($target_height-$new_height)/2, 0, 0, $target_width, $target_height, $width, $height)) { |
69
|
|
View Code Duplication |
if (!@imagecopyresampled($new_img, $img, 0, 0, 0, 0, $target_width, $target_height, $width, $height)) { |
|
|
|
|
70
|
|
|
echo _AM_MARTIN_ERROR_COULD_NOT_RESIZE_IMAGE; |
71
|
|
|
exit(0); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
ob_start(); |
75
|
|
|
// Get the image and create a thumbnail |
76
|
|
View Code Duplication |
switch ($FileType) { |
|
|
|
|
77
|
|
|
case "jpg": |
78
|
|
|
imagejpeg($new_img); |
79
|
|
|
break; |
80
|
|
|
case "png": |
81
|
|
|
imagepng($new_img); |
82
|
|
|
break; |
83
|
|
|
case "gif": |
84
|
|
|
imagegif($new_img); |
85
|
|
|
break; |
86
|
|
|
case "bmp": |
87
|
|
|
imagewbmp($new_img); |
88
|
|
|
break; |
89
|
|
|
} |
90
|
|
|
$imagevariable = ob_get_contents(); |
91
|
|
|
ob_end_clean(); |
92
|
|
|
|
93
|
|
|
//var_dump($imagevariable);exit; |
94
|
|
|
|
95
|
|
|
header("Content-type: image/jpeg"); |
96
|
|
|
header("Content-Length: " . strlen($imagevariable)); |
97
|
|
|
|
98
|
|
|
echo $imagevariable; |
99
|
|
|
exit(0); |
100
|
|
|
|
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.