Неустранимая ошибка: допустимый размер памяти

Я получаю фатальную ошибку из моего сценария изменения размера изображения, который принимает jpegs и изменяет их размеры, а затем сохраняет. Загружаемое изображение не превышает максимальное ограничение загрузки (никогда не закрывается) и на основании ошибки я не близка к пределу.

Я что-то пропустил о том, как используется память, и почему это может произойти случайным образом, но работать с изображениями, которые больше?

Fatal error: Allowed memory size of 52428800 bytes exhausted (tried to allocate 15756 bytes) in /home/content/t/w/e/myserver/html/test/includes/resize_class.php on line 34 

У меня есть файл php.ini в том же каталоге

 memory_limit = 50M post_max_size = 100M file_uploads = On upload_max_filesize = 192M 

LINE 34: $this->image = imagecreatefromjpeg($filename);

resize_calss.php: Также отметить. Пользователь загружает до 3 iamges за один раз, и я просматриваю и использую этот класс для изменения размера и сохранения больших пальцев на моем сервере

 /* * File: SimpleImage.php * Author: Simon Jarvis * Copyright: 2006 Simon Jarvis * Date: 08/11/06 * Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html * */ class SimpleImage { var $image; var $image_type; function load($filename) { $image_info = getimagesize($filename); $this->image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg($filename); } elseif( $this->image_type == IMAGETYPE_GIF ) { $this->image = imagecreatefromgif($filename); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image,$filename); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image); } } function getWidth() { return imagesx($this->image); } function getHeight() { return imagesy($this->image); } function resizeToHeight($height) { $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); } function scale($scale) { $width = $this->getWidth() * $scale/100; $height = $this->getheight() * $scale/100; $this->resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } } ?> 

Что-то, что я сделал в моем классе манипуляции с изображениями , которого этот не делает, это уничтожить исходное изображение после создания нового (например, в методе resize() ).

Попробуйте изменить метод resize() на этот

 function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); imagedestroy($this->_image); $this->image = $new_image; } 

Я бы также добавил что-то подобное в методе load()

 function load($filename) { if (is_resource($this->image)) { imagedestroy($this->image); } // and the rest } 

image re-size будет использовать много памяти, вы можете рассмотреть возможность использования ini_set для увеличения предела памяти в методе (изменение размера) в resize_class.php

связанные вопросы

  • Эффективное изменение размера изображения JPEG в PHP
  • разумный PHP memory_limit для изменения размера изображения
  • парень энтузиазма, который создает калькулятор памяти для этого

Вероятно, ваш скрипт превысил memory limit . (52 428 800 байт = 50 МБ)