| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | include('../includes/includes.inc.php'); |
|---|
| 26 | |
|---|
| 27 | $token = retreive_url_info($_SERVER['PHP_SELF']); |
|---|
| 28 | |
|---|
| 29 | $nb_arg = count($token); |
|---|
| 30 | |
|---|
| 31 | if($nb_arg == 5) |
|---|
| 32 | $img = array( |
|---|
| 33 | 'size' => $token[1], |
|---|
| 34 | 'subdir1'=> $token[2], |
|---|
| 35 | 'subdir2'=> $token[3], |
|---|
| 36 | 'filename' => $token[4], |
|---|
| 37 | 'path' => $token[2].'/'.$token[3].'/'.$token[4] |
|---|
| 38 | ); |
|---|
| 39 | |
|---|
| 40 | elseif($nb_arg == 4) |
|---|
| 41 | $img = array( |
|---|
| 42 | 'size' => null, |
|---|
| 43 | 'subdir1' => $token[1], |
|---|
| 44 | 'subdir2' => $token[2], |
|---|
| 45 | 'filename' => $token[3], |
|---|
| 46 | 'path' => $token[1].'/'.$token[2].'/'.$token[3] |
|---|
| 47 | ); |
|---|
| 48 | |
|---|
| 49 | if(ereg('x', $img['size'])) |
|---|
| 50 | { |
|---|
| 51 | list($s1, $s2) = split('x', $img['size']); |
|---|
| 52 | if(is_numeric($s1) && $s1>1) |
|---|
| 53 | $width = $s1; |
|---|
| 54 | else |
|---|
| 55 | $width = 1500; |
|---|
| 56 | if(is_numeric($s2) && $s1>1) |
|---|
| 57 | $height = $s2; |
|---|
| 58 | else |
|---|
| 59 | $height = 1125; |
|---|
| 60 | } |
|---|
| 61 | elseif(is_numeric($img['size'])) |
|---|
| 62 | { |
|---|
| 63 | $width = $img['size']; |
|---|
| 64 | $height = 1125; |
|---|
| 65 | } |
|---|
| 66 | else |
|---|
| 67 | { |
|---|
| 68 | unset($img['size']); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | if(file_exists(ALBUMPATH.'/'.$img['path'])) |
|---|
| 72 | { |
|---|
| 73 | $real_file = ALBUMPATH.'/'.$img['path']; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | if(is_null($img['size']) || $img['size']=='0x0' || $img['size']=='0') |
|---|
| 77 | { |
|---|
| 78 | header('location: /albums/'.$img['path']); |
|---|
| 79 | exit(); |
|---|
| 80 | } |
|---|
| 81 | elseif(is_numeric($width) && is_numeric($height)) |
|---|
| 82 | { |
|---|
| 83 | $sized_file = ALBUMSIZEDPATH.'/'.$img['size'].'/'.$img['subdir1'].'_'.$img['subdir2'].'_'.$img['filename']; |
|---|
| 84 | } |
|---|
| 85 | else |
|---|
| 86 | { |
|---|
| 87 | header('Location: /files/pics/nopics.png'); |
|---|
| 88 | exit(); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | if($img['path'] && file_exists($real_file)) |
|---|
| 92 | { |
|---|
| 93 | if(!file_exists($sized_file)) |
|---|
| 94 | { |
|---|
| 95 | error_log("$_DOMAIN | Creation du cache pour {$img['path']} en $width x $height"); |
|---|
| 96 | if(!is_dir(ALBUMSIZEDPATH.'/'.$img['size'])) |
|---|
| 97 | mkdir(ALBUMSIZEDPATH.'/'.$img['size']); |
|---|
| 98 | list($w, $h, $type, $attr) = getimagesize($real_file); |
|---|
| 99 | |
|---|
| 100 | switch($type) |
|---|
| 101 | { |
|---|
| 102 | case 3: |
|---|
| 103 | $src = imagecreatefrompng($real_file); |
|---|
| 104 | $ext = 'png'; |
|---|
| 105 | break; |
|---|
| 106 | case 2: |
|---|
| 107 | $src = imagecreatefromjpeg($real_file); |
|---|
| 108 | $ext = 'jpeg'; |
|---|
| 109 | break; |
|---|
| 110 | case 1: |
|---|
| 111 | $src = imagecreatefromgif($real_file); |
|---|
| 112 | $ext = 'gif'; |
|---|
| 113 | break; |
|---|
| 114 | default: |
|---|
| 115 | header('Location: /files/pics/nopics.png'); |
|---|
| 116 | exit(); |
|---|
| 117 | } |
|---|
| 118 | if($src) |
|---|
| 119 | { |
|---|
| 120 | $wh_ratio = $w/$h; |
|---|
| 121 | |
|---|
| 122 | if($w > $width || $h > $height) |
|---|
| 123 | if($wh_ratio > $width/$height) |
|---|
| 124 | { |
|---|
| 125 | $image_width = $width; |
|---|
| 126 | $image_height = floor($h*$width/$w); |
|---|
| 127 | } |
|---|
| 128 | else |
|---|
| 129 | { |
|---|
| 130 | $image_width = floor($w*$height/$h); |
|---|
| 131 | $image_height = $height; |
|---|
| 132 | } |
|---|
| 133 | else |
|---|
| 134 | { |
|---|
| 135 | header('location: /albums/'.$img['path']); |
|---|
| 136 | exit(); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | error_log("$_DOMAIN | $real_file - w:$w -> $image_width / h:$h -> $image_height path: $sized_file"); |
|---|
| 140 | |
|---|
| 141 | $image = imagecreatetruecolor ($image_width, $image_height); |
|---|
| 142 | $color_white = imagecolorallocate ( $image, 255,255,255); |
|---|
| 143 | imagefilledrectangle($image, 0,0, $image_width, $image_height, $color_white); |
|---|
| 144 | imagecopyresampled($image, $src, 0,0, 0,0, $image_width, $image_height, $w, $h); |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | switch($ext) |
|---|
| 148 | { |
|---|
| 149 | case 'jpeg': |
|---|
| 150 | imagejpeg($image, $sized_file); |
|---|
| 151 | break; |
|---|
| 152 | case 'png': |
|---|
| 153 | default: |
|---|
| 154 | imagepng($image, $sized_file); |
|---|
| 155 | break; |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | header('Location: /albums/sized/'.$img['size'].'/'.$img['subdir1'].'_'.$img['subdir2'].'_'.$img['filename']); |
|---|
| 160 | exit(); |
|---|
| 161 | } |
|---|
| 162 | else |
|---|
| 163 | { |
|---|
| 164 | header('Location: /files/pics/nopics.png'); |
|---|
| 165 | exit(); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | ?> |
|---|