May 16, 200718 yr Bonjour, Pour un projet, j'ai besoin de copier, renommer et réduire des images. J'ai donc trouver sur le net un script qui réduit les images, que j'ai ensuite légèrement modifié pour pouvoir déplacer et renommer les photos (avec un copy()). Voilà mon code <?php $tab_photos[]="photos/3000p1.jpg"; $tab_photos[]="photos/3001p1.jpg"; $tab_photos[]="photos/3002p1.jpg"; $dossier = "offres/"; if(!file_exists($dossier)) mkdir($dossier); for($i = 0; $i<count($tab_photos);$i++) { if(file_exists($dossier.$i.".jpg")) { unlink($dossier.$i.".jpg"); } $src_im = ImageCreateFromJpeg($tab_photos[$i]); $size = GetImageSize($tab_photos[$i]); $src_w = $size[0]; $src_h = $size[1]; //taille de l'image $dst_w = 150; // Contraint le rééchantillonage à une largeur fixe // Maintient le ratio de l'image $dst_h = round(($dst_w / $src_w) * $src_h); $dst_im = ImageCreateTrueColor($dst_w,$dst_h); /* ImageCopyResampled copie et rééchantillonne l'image originale*/ ImageCopyResampled($dst_im,$src_im,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h); /* ImageJpeg génère l'image*/ $tmp_image = "tmp.jpg"; ImageJpeg($dst_im,$tmp_image); ImageDestroy($dst_im); imageDestroy($src_im); //on copie et on renomme l'image réduite dans le dossier offres copy($tmp_image,$dossier.$i.".jpg"); ImageDestroy($tmp_image); } ?> Résultat : Warning: imagedestroy(): supplied argument is not a valid Image resource in c:\program files\easyphp1-8\www\diaporama\copier_photos.php on line 36Warning: imagedestroy(): supplied argument is not a valid Image resource in c:\program files\easyphp1-8\www\diaporama\copier_photos.php on line 36 Warning: imagedestroy(): supplied argument is not a valid Image resource in c:\program files\easyphp1-8\www\diaporama\copier_photos.php on line 36 Malgrè ces erreurs, les images sont bien copiées, renommées et réduites. Mais il reste toujours l'image temporaire (tmp.jpg) que j'aimerai supprimer à la fin. Si jamais vous voyez d'où vient mon erreur... Merci Edited May 16, 200718 yr by Hartycho
May 16, 200718 yr ImageDestroy ne sert pas à supprimer un fichier, cf la doc "unlink" sera plus approprié je pense
Archived
This topic is now archived and is closed to further replies.