01 <?php
02 $src = imagecreatefromjpeg($_FILES['pic']['tmp_name']);
03 // get the source image's widht and hight
04 $src_w = imagesx($src);
05 $src_h = imagesy($src);
06
07 // assign thumbnail's widht and hight
08 if($src_w > $src_h){
09 $thumb_w = 100;
10 $thumb_h = intval($src_h / $src_w * 100);
11 }else{
12 $thumb_h = 100;
13 $thumb_w = intval($src_w / $src_h * 100);
14 }
15
16 // if you are using GD 1.6.x, please use imagecreate()
17 $thumb = imagecreatetruecolor($thumb_w, $thumb_h);
18
19 // start resize
20 imagecopyresized($thumb, $src, 0, 0, 0, 0, $thumb_w, $thumb_h, $src_w, $src_h);
21
22
23 // save thumbnail
24 imagejpeg($thumb, "/var/www/html/uploads/thumb/".$_FILES['pic']['name']);
25 ?>01 <?php
02 function ImageResize (&$src, $x, $y) {
03 $dst=imagecreatetruecolor($x, $y);
04 $pals=ImageColorsTotal ($src);
05
06 for ($i=0; $i<$pals; $i++) {
07 $colors=ImageColorsForIndex ($src, $i);
08 ImageColorAllocate ($dst, $colors['red'], $colors['green'], $colors['blue']);
09
10 }
11 $scX =(imagesx ($src)-1)/$x;
12 $scY =(imagesy ($src)-1)/$y;
13 $scX2 =intval($scX/2);
14 $scY2 =intval($scY/2);
15
16 for ($j = 0; $j < ($y); $j++) {
17 $sY = intval($j * $scY);
18 $y13 = $sY + $scY2;
19 for ($i = 0; $i < ($x); $i++) {
20 $sX = intval($i * $scX);
21 $x34 = $sX + $scX2;
22 $c1 = ImageColorsForIndex ($src, ImageColorAt ($src, $sX, $y13));
23 $c2 = ImageColorsForIndex ($src, ImageColorAt ($src, $sX, $sY));
24 $c3 = ImageColorsForIndex ($src, ImageColorAt ($src, $x34, $y13));
25 $c4 = ImageColorsForIndex ($src, ImageColorAt ($src, $x34, $sY));
26 $r = ($c1['red']+$c2['red']+$c3['red']+$c4['red'])/4;
27 $g = ($c1['green']+$c2['green']+$c3['green']+$c4['green'])/4;
28 $b = ($c1['blue']+$c2['blue']+$c3['blue']+$c4['blue'])/4;
29 ImageSetPixel ($dst, $i, $j, ImageColorClosest ($dst, $r, $g, $b));
30 }
31 }
32 return ($dst);
33 }
34 ?>