Bonjour à tous,
J'ai un code qui crée des miniatures après upload des photos. Quand j'envoi des photos de 400ko environ il n'y a aucun soucis mais lorsque les photos ont un poids de 1MO et plus il y a problème "Fatal error: Allowed memory size......"
Voici le code qui crée les miniatures:
<?php
function createthumb($name,$filename,$new_w,$new_h){
$system=explode('.',$name);
if (preg_match('/jpg|jpeg|JPG|JPEG/',$system[1])){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match('/png/',$system[1])){
$src_img=imagecreatefrompng($name);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
?>
et ce qu'il y a dans ma page pour 6 photos donc ce code 6 fois de suite:
<?php
if (empty($dest_fichier1))
{
$photo1 = "default.jpg";
}
else
{
$photo1 = $dest_fichier1;
createthumb($dest_dossier . $dest_fichier1, $dossier_thumbs . $dest_fichier1, $taille_thumbs1, $qualite_thumbs1);
createthumb($dest_dossier . $dest_fichier1, $dossier_final . $dest_fichier1, $taille_thumbs2, $qualite_thumbs2);
unlink($dest_dossier . $dest_fichier1);
}
?>
Quelles sont les solutions ?
D'avance merci.