Aller au contenu
View in the app

A better way to browse. Learn more.

Next

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[RESOLU][PHP] problème avec ImageDestroy

Featured Replies

Posté(e)

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 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

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 :transpi:

Modifié par Hartycho

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.