-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResizeImage.php
More file actions
33 lines (26 loc) · 824 Bytes
/
ResizeImage.php
File metadata and controls
33 lines (26 loc) · 824 Bytes
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
<?php
function resizeImage($filename, $max_width, $max_height)
{
list($orig_width, $orig_height) = getimagesize($filename);
$width = $orig_width;
$height = $orig_height;
# taller
if ($height > $max_height) {
$width = ($max_height / $height) * $width;
$height = $max_height;
}
# wider
if ($width > $max_width) {
$height = ($max_width / $width) * $height;
$width = $max_width;
}
$image_p = imagecreatetruecolor($width, $height);
imageAlphaBlending($image_p, false);
imageSaveAlpha($image_p, true);
$image = imagecreatefrompng($filename);
imageAlphaBlending($image, false);
imageSaveAlpha($image, true);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height);
return $image_p;
}
?>