forked from legale/rapida
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergelogo.php_
129 lines (95 loc) · 4.18 KB
/
mergelogo.php_
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
function is_url( $text )
{
//273 - FILTER_VALIDATE_URL 131072 - FILTER_FLAG_HOST_REQUIRED
return filter_var( $text, 273, 131072) !== false;
}
function url_exists($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$code = (int)substr($code, 0, 1);
if(in_array($code, array(2,3))){
$status = true;
}else{
$status = false;
}
curl_close($ch);
return $status;
}
function LoadImg($src, $logo, $text = null)
{
if( !file_exists($logo) ){
header('HTTP/1.0 404 Not Found');
return false;
}
$src = trim($src,'/');
if(!is_url($src) && !file_exists($src) ){
$src = 'http://' . $_SERVER['SERVER_NAME'] . '/' . $src;
if(url_exists($src)){
$tmp = tempnam( sys_get_temp_dir() , 'tmp_');
copy($src, $tmp);
$src = $tmp;
}else{
header('HTTP/1.0 404 Not Found');
return false;
}
}
// логотип
$logo = imagecreatefrompng($logo);
// ширина логотипа
$logo_width = imagesx($logo);
// высота логотипа
$logo_height = imagesy($logo);
// изм. размера в процентах
$percent = '';
// тип итогового изображения
$res_type = 'png';
if(!list($w, $h) = getimagesize($src)) return "Unsupported picture type!";
// получаем изображение из исходного файла в зависимости от типа файла
$type = image_type_to_mime_type(exif_imagetype($src));
switch($type){
case 'image/bmp': $image = imagecreatefromwbmp($src); break;
case 'image/gif': $image = imagecreatefromgif($src); break;
case 'image/jpeg': $image = imagecreatefromjpeg($src); break;
case 'image/png': $image = imagecreatefrompng($src); break;
default : return "Unsupported picture type!";
}
// тип содержимого
header("Content-Type: image/".$res_type);
// получение новых размеров
list($width, $height) = getimagesize($src);
$percent = 1;
$new_width = $width * $percent;
$new_height = $height * $percent;
$dst_x = ($new_width - $width) / 2 ;
$dst_y = ($new_height - $height) / 2 ;
// создаем черный квадрат
$square = imagecreatetruecolor($new_width, $new_height);
//устанавливаем цвет RGB
$color = imagecolorallocate($square, 255, 90, 35);
// создаем итоговый квадрат с заданным цветом
imagefilledrectangle($square, 0, 0, $new_width, $new_height, $color);
// ресэмплирование imagecopyresampled(итоговое изображение, накладываемое изображение, коорд. точки на итог. изобр.,
// коорд. точки на накл. изобр, шир. и выс. на итог. изобр., шир. и выс. исх. изобр)
imagecopyresampled($square, $image, $dst_x, $dst_y, 0, 0, $width, $height, $width, $height);
//накладываем изображение логотипа на изображение
$newlogo_width = $width * 0.5;
$ratio = $logo_width / $newlogo_width;
$newlogo_height = $logo_height / $ratio;
imagecopyresampled($square, $logo, $width - ($width * 0.02 + $newlogo_width), $height - ($height * 0.815 + $newlogo_height), 0, 0, $newlogo_width, $newlogo_height, $logo_width, $logo_height);
if(isset($text)) {
$white = imagecolorallocate ($square, 255, 255, 255);
imagettftext ($square, 60, 0, $width * 0.02, $height - $height * 0.03, $white, "captcha/verdana.ttf", $text);
}
// вывод
switch($res_type){
case 'bmp': return imagewbmp($square, null, 100); break;
case 'gif': return imagegif($square, null, 100); break;
case 'jpg': return imagejpeg($square, null, 100); break;
case 'png': return imagepng($square, null, 9, PNG_NO_FILTER); break;
default : return "Unsupported picture type!";
}
}
$img = LoadImg($_GET['p'], $_GET['l'], @$_GET['text']);