image.php
1.94 KB
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
<?php
function upload_ImageResize($upload,$option){
$type = substr(strrchr($upload['name'],"."),1);
$newWidth = $option["width"];
$newHeight = $option["height"];
$nameFile = mktime() . "-" .rand(1,10000). "-" .rand(1,10000) . "." . $type;
$save_image = $option["upload_path"] . $nameFile;
$img = $upload["tmp_name"];
switch($type){
case "jpg":
$function_image_create = "ImageCreateFromJpeg";
$function_image_new = "ImageJpeg";
case "jpeg":
$function_image_create = "ImageCreateFromJpeg";
$function_image_new = "ImageJpeg";
break;
case "png":
$function_image_create = "ImageCreateFromPng";
$function_image_new = "ImagePNG";
break;
case "gif":
$function_image_create = "ImageCreateFromGif";
$function_image_new = "ImageGif";
break;
default:
$function_image_create = "ImageCreateFromJpeg";
$function_image_new = "ImageJpeg";
break;
}
$srcImage = @$function_image_create($img);
$srcWidth = ImageSX($srcImage);
$srcHeight = ImageSY($srcImage);
if ( ($newWidth < $srcWidth) || ($newHeight < $srcHeight) ) {
if( $srcWidth < $srcHeight ){
$destWidth = $newWidth * $srcWidth/$srcHeight;
$destHeight = $newHeight;
}else{
$destWidth = $newWidth;
$destHeight = $newHeight * $srcHeight/$srcWidth;
}
}else{ $destWidth = $srcWidth;$destHeight = $srcHeight;}
$destImage = imagecreatetruecolor($destWidth, $destHeight);
ImageCopyResampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
/*
if(isset($option['str']) && strlen($option['str'])>0){
$colorGrey=imagecolorallocate($destImage, 192, 192, 192);
$height_str = $destHeight-7;
imagettftext($destImage,15,0,7,$height_str,$colorGrey,"{$_SERVER['DOCUMENT_ROOT']}/libs/fonts/ds_zombi.ttf",$option['str']);
} */
@$function_image_new($destImage,$save_image,100);
ImageDestroy( $srcImage );
ImageDestroy( $destImage );
return $nameFile;
}
?>