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
|
function buildPhoto($dir,$photo){
$tempPath = $GLOBALS['PATHPHOTO'].$dir.'/'.'temp/';
if(!is_dir($tempPath)){
mkdir($tempPath, 0755);
}
if(!is_dir($tempPath.$GLOBALS['WIDTH'].'/')){
mkdir($tempPath.$GLOBALS['WIDTH'].'/', 0755);
}
$img_dest = $tempPath.$GLOBALS['WIDTH'].'/'.$photo;
if(!file_exists($img_dest)){
$src_img = $GLOBALS['PATHPHOTO'].$dir.'/'.$photo;
$size = GetImageSize($src_img);
$src_w = $size[0]; $src_h = $size[1];
$coef = diviseurImage($src_w,$src_h);
$dst_w = $src_w/$coef; $dst_h = $src_h/$coef;
echo $src_img;
if(file_exists($src_img)){
echo "ok";
}
else{
echo "nonok";
}
//$dst_im = ImageCreate($dst_w,$dst_h);
$dst_im = ImageCreateTrueColor($dst_w,$dst_h);
if($dst_im != false){
$src_im = imagecreatefromjpeg($src_img);
echo $src_im;
//$src_im = false;
if($src_im != false){
if(ImageCopyResized($dst_im,$src_im,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h)){
//ImageCopyResampled($dst_im,$src_im,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
if(ImageJpeg($dst_im,$img_dest)){
ImageDestroy($dst_im);
ImageDestroy($src_im);
}
else{
echo 'erreur ImageJpeg($dst_im,$img_dest) ';
return($img_dest);
}
}
else{
echo 'erreur ImageCopyResized($dst_im,$src_im,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h) ';
return($img_dest);
}
}
else{
echo 'erreur ImageCreateFromJpeg($src_img); ';
return($img_dest);
}
}
else{
echo 'erreur ImageCreateTrueColor($dst_w,$dst_h); ';
return($img_dest);
}
}
return($img_dest);
} |
Partager