@@ -11,81 +11,81 @@ |
||
11 | 11 | |
12 | 12 | function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE){ |
13 | 13 | |
14 | - // First, calculate the height. |
|
15 | - $height = intval($newWidth / $imgWidth * $imgHeight); |
|
14 | + // First, calculate the height. |
|
15 | + $height = intval($newWidth / $imgWidth * $imgHeight); |
|
16 | 16 | |
17 | - // If the height is too large, set it to the maximum height and calculate the width. |
|
18 | - if ($height > $newHeight) { |
|
17 | + // If the height is too large, set it to the maximum height and calculate the width. |
|
18 | + if ($height > $newHeight) { |
|
19 | 19 | |
20 | - $height = $newHeight; |
|
21 | - $newWidth = intval($height / $imgHeight * $imgWidth); |
|
22 | - } |
|
20 | + $height = $newHeight; |
|
21 | + $newWidth = intval($height / $imgHeight * $imgWidth); |
|
22 | + } |
|
23 | 23 | |
24 | - // If we don't allow upsizing check if the new width or height are too big. |
|
25 | - if (!$upsize) { |
|
26 | - // If the given width is larger then the image height, then resize it. |
|
27 | - if ($newWidth > $imgWidth) { |
|
28 | - $newWidth = $imgWidth; |
|
29 | - $height = intval($newWidth / $imgWidth * $imgHeight); |
|
30 | - } |
|
24 | + // If we don't allow upsizing check if the new width or height are too big. |
|
25 | + if (!$upsize) { |
|
26 | + // If the given width is larger then the image height, then resize it. |
|
27 | + if ($newWidth > $imgWidth) { |
|
28 | + $newWidth = $imgWidth; |
|
29 | + $height = intval($newWidth / $imgWidth * $imgHeight); |
|
30 | + } |
|
31 | 31 | |
32 | - // If the given height is larger then the image height, then resize it. |
|
33 | - if ($height > $imgHeight) { |
|
34 | - $height = $imgHeight; |
|
35 | - $newWidth = intval($height / $imgHeight * $imgWidth); |
|
36 | - } |
|
37 | - } |
|
32 | + // If the given height is larger then the image height, then resize it. |
|
33 | + if ($height > $imgHeight) { |
|
34 | + $height = $imgHeight; |
|
35 | + $newWidth = intval($height / $imgHeight * $imgWidth); |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - if ($ratio == true) |
|
40 | - { |
|
41 | - $source_aspect_ratio = $imgWidth / $imgHeight; |
|
42 | - $thumbnail_aspect_ratio = $newWidth / $newHeight; |
|
43 | - if ($imgWidth <= $newWidth && $imgHeight <= $newHeight) { |
|
44 | - $newWidth = $imgWidth; |
|
45 | - $newHeight = $imgHeight; |
|
46 | - } elseif ($thumbnail_aspect_ratio > $source_aspect_ratio) { |
|
47 | - $newWidth = (int) ($newHeight * $source_aspect_ratio); |
|
48 | - $newHeight = $newHeight; |
|
49 | - } else { |
|
50 | - $newWidth = $newWidth; |
|
51 | - $newHeight = (int) ($newWidth / $source_aspect_ratio); |
|
52 | - } |
|
53 | - } |
|
39 | + if ($ratio == true) |
|
40 | + { |
|
41 | + $source_aspect_ratio = $imgWidth / $imgHeight; |
|
42 | + $thumbnail_aspect_ratio = $newWidth / $newHeight; |
|
43 | + if ($imgWidth <= $newWidth && $imgHeight <= $newHeight) { |
|
44 | + $newWidth = $imgWidth; |
|
45 | + $newHeight = $imgHeight; |
|
46 | + } elseif ($thumbnail_aspect_ratio > $source_aspect_ratio) { |
|
47 | + $newWidth = (int) ($newHeight * $source_aspect_ratio); |
|
48 | + $newHeight = $newHeight; |
|
49 | + } else { |
|
50 | + $newWidth = $newWidth; |
|
51 | + $newHeight = (int) ($newWidth / $source_aspect_ratio); |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - $imgString = file_get_contents($image); |
|
55 | + $imgString = file_get_contents($image); |
|
56 | 56 | |
57 | - $imageFromString = imagecreatefromstring($imgString); |
|
58 | - $tmp = imagecreatetruecolor($newWidth, $newHeight); |
|
59 | - #imagealphablending($tmp, false); |
|
60 | - #imagesavealpha($tmp, true); |
|
61 | - imagecopyresampled( |
|
62 | - $tmp, |
|
63 | - $imageFromString, |
|
64 | - 0, |
|
65 | - 0, |
|
66 | - 0, |
|
67 | - 0, |
|
68 | - $newWidth, |
|
69 | - $newHeight, |
|
70 | - $imgWidth, |
|
71 | - $imgHeight |
|
72 | - ); |
|
57 | + $imageFromString = imagecreatefromstring($imgString); |
|
58 | + $tmp = imagecreatetruecolor($newWidth, $newHeight); |
|
59 | + #imagealphablending($tmp, false); |
|
60 | + #imagesavealpha($tmp, true); |
|
61 | + imagecopyresampled( |
|
62 | + $tmp, |
|
63 | + $imageFromString, |
|
64 | + 0, |
|
65 | + 0, |
|
66 | + 0, |
|
67 | + 0, |
|
68 | + $newWidth, |
|
69 | + $newHeight, |
|
70 | + $imgWidth, |
|
71 | + $imgHeight |
|
72 | + ); |
|
73 | 73 | |
74 | - switch ($mimeType) { |
|
75 | - case "jpeg": |
|
76 | - case "jpg": |
|
77 | - imagejpeg($tmp, $image, 90); |
|
78 | - break; |
|
79 | - case "png": |
|
80 | - imagepng($tmp, $image, 0); |
|
81 | - break; |
|
82 | - case "gif": |
|
83 | - imagegif($tmp, $image); |
|
84 | - break; |
|
85 | - default: |
|
86 | - throw new \Exception(" Only jpg, jpeg, png and gif files can be resized "); |
|
87 | - break; |
|
88 | - } |
|
74 | + switch ($mimeType) { |
|
75 | + case "jpeg": |
|
76 | + case "jpg": |
|
77 | + imagejpeg($tmp, $image, 90); |
|
78 | + break; |
|
79 | + case "png": |
|
80 | + imagepng($tmp, $image, 0); |
|
81 | + break; |
|
82 | + case "gif": |
|
83 | + imagegif($tmp, $image); |
|
84 | + break; |
|
85 | + default: |
|
86 | + throw new \Exception(" Only jpg, jpeg, png and gif files can be resized "); |
|
87 | + break; |
|
88 | + } |
|
89 | 89 | |
90 | 90 | } |
91 | 91 |