-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThumbImage.php
134 lines (108 loc) · 3.62 KB
/
ThumbImage.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
131
132
133
134
<?php
//Image Storage Directory
function CreateThumb_40($srcpath,$fileName,$trgtpath)
{
$img_dir=$trgtpath;
$img = explode('.', $fileName);
//Original File
$originalImage=$srcpath;
//Thumbnail file name File
$image_filePath=$srcpath;
$img_fileName=$fileName;
$img_thumb = $img_dir . $img_fileName;
$extension = strtolower($img[1]);
//Check the file format before upload
if(in_array($extension , array('jpg','jpeg', 'gif', 'png', 'bmp'))){
//Find the height and width of the image
$newwidth=40;
$newheight=40;
//---------- To create thumbnail of image---------------
if($extension=="jpg" || $extension=="jpeg" ){
$src = imagecreatefromjpeg($srcpath);
}
else if($extension=="png"){
$src = imagecreatefrompng($srcpath);
}
else{
$src = imagecreatefromgif($srcpath);
}
list($width,$height)=getimagesize($srcpath);
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
//Create thumbnail image
$createImageSave=imagejpeg($tmp,$img_thumb,100);
}
}
function CreateProfileThumb($srcpath,$fileName,$trgtpath)
{
$img_dir=$trgtpath;
$img = explode('.', $fileName);
//Original File
$originalImage=$srcpath;
//Thumbnail file name File
$image_filePath=$srcpath;
$img_fileName=$fileName;
$img_thumb = $img_dir . $img_fileName;
$extension = strtolower($img[1]);
//Check the file format before upload
if(in_array($extension , array('jpg','jpeg', 'gif', 'png', 'bmp'))){
//Find the height and width of the image
$newwidth=300;
$newheight=300;
//---------- To create thumbnail of image---------------
if($extension=="jpg" || $extension=="jpeg" ){
$src = imagecreatefromjpeg($srcpath);
}
else if($extension=="png"){
$src = imagecreatefrompng($srcpath);
}
else{
$src = imagecreatefromgif($srcpath);
}
list($width,$height)=getimagesize($srcpath);
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
//Create thumbnail image
$createImageSave=imagejpeg($tmp,$img_thumb,100);
}
}
function CreateThumb_90($srcpath,$fileName,$trgtpath)
{
$img_dir=$trgtpath;
$img = explode('.', $fileName);
//Original File
$originalImage=$srcpath;
//Thumbnail file name File
$image_filePath=$srcpath;
$img_fileName=$fileName;
$img_thumb = $img_dir . $img_fileName;
$extension = strtolower($img[1]);
//Check the file format before upload
if(in_array($extension , array('jpg','jpeg', 'gif', 'png', 'bmp'))){
//Find the height and width of the image
$newwidth=90;
$newheight=90;
//---------- To create thumbnail of image---------------
if($extension=="jpg" || $extension=="jpeg" ){
$src = imagecreatefromjpeg($srcpath);
}
else if($extension=="png"){
$src = imagecreatefrompng($srcpath);
}
else{
$src = imagecreatefromgif($srcpath);
}
list($width,$height)=getimagesize($srcpath);
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
//Create thumbnail image
$createImageSave=imagejpeg($tmp,$img_thumb,100);
}
}
if(isset($_REQUEST['img']))
{
CreateThumb_90($_SERVER["DOCUMENT_ROOT"].'/upload/profilePhotos/'.$_REQUEST['img'],$_REQUEST['img'],$_SERVER["DOCUMENT_ROOT"].'/upload/profilePhotos/thumb/t_90/');
CreateThumb_40($_SERVER["DOCUMENT_ROOT"].'/upload/profilePhotos/'.$_REQUEST['img'],$_REQUEST['img'],$_SERVER["DOCUMENT_ROOT"].'/upload/profilePhotos/thumb/t_40/');
CreateProfileThumb($_SERVER["DOCUMENT_ROOT"].'/upload/profilePhotos/'.$_REQUEST['img'],$_REQUEST['img'],$_SERVER["DOCUMENT_ROOT"].'/upload/profilePhotos/');
}
?>