-
Notifications
You must be signed in to change notification settings - Fork 0
/
customresize.php
130 lines (102 loc) · 3.3 KB
/
customresize.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
129
130
<?php
include "appdata/conf.php";
$imgname = $folder . $_POST["img"];
$full_width = intval($_POST["full_width"]);
$full_height = intval($_POST["full_Height"]);
$resized_width = intval($_POST["resized_width"]);
$resized_height = intval($_POST["resized_height"]);
$start_x = intval($_POST["start_x"]);
$start_y = intval($_POST["start_y"]);
$fastemaal = $_POST["fastemaal"];
$ny_width = intval($_POST["ny_width"]);
$ny_height = intval($_POST["ny_height"]);
$fileinfomation = getimagesize($imgname);
$width = $fileinfomation[0];
$height = $fileinfomation[1];
$mime = $fileinfomation["mime"];
$type = substr(strrchr($mime, '/'), 1);
$img = false;
switch ($type) {
case 'jpeg':
$img = imagecreatefromjpeg($imgname);
$new_image_ext = 'jpg';
break;
case 'png':
$img = imagecreatefrompng($imgname);
$new_image_ext = 'png';
imagealphablending($img, false);
imagesavealpha($img, true);
break;
case 'bmp':
$img = imagecreatefrombmp($imgname);
$new_image_ext = 'bmp';
break;
case 'gif':
$img = imagecreatefromgif($imgname);
$new_image_ext = 'gif';
break;
case 'vnd.wap.wbmp':
$img = imagecreatefromwbmp($imgname);
$new_image_ext = 'bmp';
break;
case 'xbm':
$img = imagecreatefromxbm($imgname);
$new_image_ext = 'xbm';
break;
default:
$img = imagecreatefromjpeg($imgname);
$new_image_ext = 'jpg';
}
$after_croped_width = round(($resized_width/$full_width)*$width);
$after_croped_height = round(($resized_height/$full_height)*$height);
$croppin_x = round(($start_x/$full_width)*$width);
$croppin_y = round(($start_y/$full_height)*$height);
// bool imagecopy ( $dst_im , $src_im , $dst_x , $dst_y , $src_x , $src_y , $src_w , $src_h )
$img = imagecrop($img, array("x"=>$croppin_x, "y"=>$croppin_y, "width"=>$after_croped_width, "height"=>$after_croped_height));
switch ($type) {
case 'jpeg':
imagejpeg($img, $imgname);
break;
case 'png':
imagepng($img, $imgname);
break;
case 'bmp':
imagebmp($img, $imgname);
break;
case 'gif':
imagegif($img, $imgname);
break;
case 'vnd.wap.wbmp':
imagewbmp($img, $imgname);
break;
case 'xbm':
imagexbm($img, $imgname);
break;
default:
imagejpeg($img, $imgname);
}
imagedestroy($img);
if ($fastemaal == "1") {
/*$new_image = imagecreatetruecolor($ny_width, $ny_height);
$aspect1 = $ny_height / $ny_width;
$aspect1_o = $ny_width / $ny_height;
$aspect2 = $after_croped_height / $after_croped_width;
if ($aspect1 < $aspect2) {
// lut i top og bund
$start_y_f = round(($start_y/$full_height)*$height);
imagecopy($img, $img, 0, $start_y_f, 0, 0, $ny_width, $ny_height);
} else if ($aspect1 > $aspect2) {
} else {
imagecopy($img, $img, 0, 0, 0, 0, $ny_width, $ny_height);
}*/
include 'php_image_magician.class.php';
$img = new imageLib($imgname);
$img->resizeImage($ny_width, $ny_height, 4);
$img->saveImage($imgname);
}
list($w, $h, $type, $attr) = getimagesize($imgname);
echo json_encode(array(
"width"=>$w,
"height"=>$h,
"class"=> ($w > $h ? 'lanscape' : ($w == $h ? 'kvadradic' : 'protrat'))
));