Ejemplo: en el directorio donde esta guardado mi archivo php, llamado thumbs.php, tengo una imagen de nombre "imagen.php" el script me genera una nueva imagen de nombre "thumb_imagen.php" de la mitad de su tamaño; y asi sucesivamente con las demas imagenes del directorio.
Esta funcionando, pero luego de hacer varias imagenes, y mas si tienen varios Kb, me aparece el siguiente error y deja de crear mas imagenes:
Código HTML:
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 512 bytes) in C:\AppServ\www\imagenes\thumbs\galeria\thumbs.php on line 9
Código PHP:
imagedestroy($fuente);
imagedestroy($imagen);
El codigo es:
Código PHP:
<?php
function imagenes_escala($archivo,$escala)
{
$fuente = imagecreatefromjpeg($archivo);
$imgAncho = imagesx($fuente);
$imgAlto =imagesy($fuente);
$ancho = $imgAncho*$escala;
$alto = $imgAlto*$escala;
$imagen = imagecreatetruecolor($ancho,$alto);
imagecopyresampled($imagen,$fuente,0,0,0,0,$ancho,$alto,$imgAncho,$imgAlto);
imagejpeg($imagen,"thumb_".$archivo);
imagedestroy($fuente);
imagedestroy($imagen);
}
?>
<?php
$escala= 0.5;
$files = "";
$n=1;
foreach (glob("*.jpg") as $key => $fileName)
{
$files[$n]= "$fileName";
$n=$n+1;
}
for ($u="1"; $u<"$n"; $u++)
{
$archivo = $files[$u];
imagenes_escala($archivo,$escala);
}
?>