Pregunta

Estoy usando un código que subir una imagen, poner la imagen en la carpeta de "redimensionar", cambiar el tamaño de la imagen, mover la imagen a otra carpeta, a continuación, eliminar la imagen de la carpeta "redimensionar", sin embargo yo' estoy consiguiendo el error siguiente:

" Fatal error: Permitido el tamaño de la memoria de 33554432 bytes agotado (tratado de asignar 14172 bytes) en /home/photogra/public_html/administrator/components/com_gallery/admin.gallery.php en la línea 649 "

Las imágenes no son aún grandes! (Por ejemplo. 265kb)

Este es el código que estoy usando (con los números de línea):

635         move_uploaded_file($_FILES['image']['tmp_name'],$mainframe->getCfg( 'absolute_path' ) ."/virtualgallery/images/resize/$newname");
636         
637         /* resize images - width 600px */   
638         $docRoot = $GLOBALS['mosConfig_absolute_path'];
639         $pathToImages = $docRoot.'/virtualgallery/images/resize/';
640         $pathToThumbs = $docRoot.'/virtualgallery/images/';
641         $thumbHeight = 600;
642         
643         $dir = opendir( $pathToImages );
644         while (false !== ($fname = readdir( $dir ))) {
645             $info = pathinfo($pathToImages . $fname);
646             if ( strtolower($info['extension']) == 'jpg' ) {
647                 $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
648                 $width = imagesx( $img );
649                 $height = imagesy( $img );
650                 $new_width = floor( $width * ( $thumbHeight / $height ) );
651                 $new_height = $thumbHeight;
652                 $tmp_img = imagecreatetruecolor( $new_width, $new_height );
653                 imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
654                 imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
655             };
656         };
657         closedir( $dir );
658         
659         /* delete file(s) from resize folder */
660         $dir = $docRoot.'/virtualgallery/images/resize/';
661         foreach(glob($dir.'*.*') as $v) {
662             unlink($v);
663         };

También cuando llegue ese error, las imágenes se queda pegada en la carpeta de "redimensionar" .. Si alguien puede ayudar, eso sería fantástico! :)

¿Fue útil?

Solución

Usted está tratando de cambiar el tamaño de todas las imágenes en un directorio sin liberar la memoria después de cada uno. Trate de añadir

imagedestroy($img);
imagedestroy($tmp_img);

Para empezar. Además, desvincular la imagen tan pronto como haya terminado con él en lugar de iterar sobre el directorio por segunda vez.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top