|
1 <?php |
|
2 header ("Content-type: image/jpeg"); |
|
3 $file_name=$_GET['f']; |
|
4 $crop_height=$_GET['h']; |
|
5 $crop_width=$_GET['w']; |
|
6 $file_type= explode('.', $file_name); |
|
7 $file_type = $file_type[count($file_type) -1]; |
|
8 $file_type=strtolower($file_type); |
|
9 |
|
10 $original_image_size = getimagesize($file_name); |
|
11 $original_width = $original_image_size[0]; |
|
12 $original_height = $original_image_size[1]; |
|
13 |
|
14 if($file_type=='jpg') |
|
15 { |
|
16 $original_image_gd = imagecreatefromjpeg($file_name); |
|
17 } |
|
18 |
|
19 if($file_type=='gif') |
|
20 { $original_image_gd = imagecreatefromgif($file_name); |
|
21 } |
|
22 |
|
23 if($file_type=='png') |
|
24 { |
|
25 $original_image_gd = imagecreatefrompng($file_name); |
|
26 } |
|
27 |
|
28 $cropped_image_gd = imagecreatetruecolor($crop_width, $crop_height); |
|
29 $wm = $original_width /$crop_width; |
|
30 $hm = $original_height /$crop_height; |
|
31 $h_height = $crop_height/2; |
|
32 $w_height = $crop_width/2; |
|
33 |
|
34 if($original_width > $original_height ) |
|
35 { |
|
36 $adjusted_width =$original_width / $hm; |
|
37 $half_width = $adjusted_width / 2; |
|
38 $int_width = $half_width - $w_height; |
|
39 |
|
40 imagecopyresampled($cropped_image_gd ,$original_image_gd ,-$int_width,0,0,0, $adjusted_width, $crop_height, $original_width , $original_height ); |
|
41 } |
|
42 elseif(($original_width < $original_height ) || ($original_width == $original_height )) |
|
43 { |
|
44 $adjusted_height = $original_height / $wm; |
|
45 $half_height = $adjusted_height / 2; |
|
46 $int_height = $half_height - $h_height; |
|
47 |
|
48 imagecopyresampled($cropped_image_gd , $original_image_gd ,0,-$int_height,0,0, $crop_width, $adjusted_height, $original_width , $original_height ); |
|
49 } |
|
50 else { |
|
51 |
|
52 imagecopyresampled($cropped_image_gd , $original_image_gd ,0,0,0,0, $crop_width, $crop_height, $original_width , $original_height ); |
|
53 } |
|
54 imagejpeg($cropped_image_gd); |
|
55 |
|
56 ?> |