par
bobo » 16 janv. 2008, 12:10
Bonjour,
Alors voila j'ai un probléme aveec cette fonction...
A la base elle était faite pour créer de jpg png et j'ai rajouter pour redimensionner des gif
Mais le probléme c'est que tout marche sauf pour les gif qui me renvoi pas l'image
Savez vous d'ou vient le probléme???
function create_thumbs($d,$file, $w, $h) {
global $upload;
$sfile = $upload . $file;
$dfile = $d . $file;
switch (getextension($sfile)) {
case 'jpg':
case 'jpeg':
$simg = imagecreatefromjpeg($sfile);
break;
case 'png':
$simg = imagecreatefrompng($sfile);
break;
case 'gif':
$simg = imagecreatefromgif($sfile);
break;
}
$currwidth = imagesx($simg);
$currheight = imagesy($simg);
//set the dimensions of the thumbnail
if ($currheight > $currwidth ) {
$zoom = $h / $currheight;
$newheight = $h;
$newwidth = $currwidth * $zoom;
$dimension=1;
} else {
$zoom = $w / $currwidth;
$newwidth = $w;
$dimension=0;
$newheight = $currheight * $zoom;
}
//create the resource img for the thumbnail
$dimg = imagecreate($newwidth, $newheight);
//convert truecolor immage resource to palette image resource (so we can count the colors...)
imagetruecolortopalette($simg, true, 256);
$palsize = ImageColorsTotal($simg);
for ($i = 0; $i < $palsize; $i++) {
$colors = ImageColorsForIndex($simg, $i);
ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);
}
imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
switch (getextension($sfile)) {
case 'jpg':
case 'jpeg':
imagejpeg($dimg, $dfile);
break;
case 'png':
imagepng($dimg, $dfile);
break;
case 'gif':
$simg = imagecreatefromgif($sfile);
break;
}
ImageDestroy($simg);
ImageDestroy($dimg);
}
Bonjour,
Alors voila j'ai un probléme aveec cette fonction...
A la base elle était faite pour créer de jpg png et j'ai rajouter pour redimensionner des gif
Mais le probléme c'est que tout marche sauf pour les gif qui me renvoi pas l'image :(
Savez vous d'ou vient le probléme??? :(
[php]function create_thumbs($d,$file, $w, $h) {
global $upload;
$sfile = $upload . $file;
$dfile = $d . $file;
switch (getextension($sfile)) {
case 'jpg':
case 'jpeg':
$simg = imagecreatefromjpeg($sfile);
break;
case 'png':
$simg = imagecreatefrompng($sfile);
break;
case 'gif':
$simg = imagecreatefromgif($sfile);
break;
}
$currwidth = imagesx($simg);
$currheight = imagesy($simg);
//set the dimensions of the thumbnail
if ($currheight > $currwidth ) {
$zoom = $h / $currheight;
$newheight = $h;
$newwidth = $currwidth * $zoom;
$dimension=1;
} else {
$zoom = $w / $currwidth;
$newwidth = $w;
$dimension=0;
$newheight = $currheight * $zoom;
}
//create the resource img for the thumbnail
$dimg = imagecreate($newwidth, $newheight);
//convert truecolor immage resource to palette image resource (so we can count the colors...)
imagetruecolortopalette($simg, true, 256);
$palsize = ImageColorsTotal($simg);
for ($i = 0; $i < $palsize; $i++) {
$colors = ImageColorsForIndex($simg, $i);
ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);
}
imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
switch (getextension($sfile)) {
case 'jpg':
case 'jpeg':
imagejpeg($dimg, $dfile);
break;
case 'png':
imagepng($dimg, $dfile);
break;
case 'gif':
$simg = imagecreatefromgif($sfile);
break;
}
ImageDestroy($simg);
ImageDestroy($dimg);
}[/php]