kalex | La fonction barbare que j'ai faite (non y pas de commentaire ) :
Code :
- function img_resize($name, $image, $size, $r_width = 160, $r_height = 120){
- $width = $size[0];
- $height = $size[1];
- if($size[2] == 1)
- $img = imagecreatefromgif($image);
- elseif($size[2] == 2)
- $img = imagecreatefromjpeg($image);
- elseif($size[2] == 3)
- $img = imagecreatefrompng($image);
- if(!isset($img)) return FALSE;
- $scale = $height / $width;
- $r_scale = $r_height / $r_width;
- if($scale < $r_scale){
- $per = $scale * 100 / $r_scale;
- $r_height = round($r_height * $per / 100);
- }elseif($scale > $r_scale){
- $per = $r_scale * 100 / $scale;
- $r_width = round($r_width * $per / 100);
- }
- $new = imagecreatetruecolor($r_width, $r_height);
- if(imagecopyresampled($new, $img, 0, 0, 0, 0, $r_width, $r_height, $width, $height)){
- if($size[2] == 1)
- imagegif($new, '../img/small/'.$name);
- elseif($size[2] == 2)
- imagejpeg($new, '../img/small/'.$name, 80);
- elseif($size[2] == 3){
- imagetruecolortopalette($new, FALSE, 180);
- imagepng($new, '../img/small/'.$name);
- }
- return TRUE;
- }else
- return FALSE;
- }
|
Oui oui, c'est codé vite fait. |