Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 致命错误:允许的内存大小_Php - Fatal编程技术网

Php 致命错误:允许的内存大小

Php 致命错误:允许的内存大小,php,Php,我的图像调整脚本出现了一个致命错误,该脚本接受JPEG并调整大小,然后保存。我上传的图像未超过最大上传限制从不关闭,基于错误,我未接近该限制 我是否遗漏了一些关于内存是如何使用的,以及为什么它会随机失效,但会处理更大的图像 我在同一个目录中有一个php.ini文件 memory_limit = 50M post_max_size = 100M file_uploads = On upload_max_filesize = 192M 第34行:$this->image=imagecreatefr

我的图像调整脚本出现了一个致命错误,该脚本接受JPEG并调整大小,然后保存。我上传的图像未超过最大上传限制从不关闭,基于错误,我未接近该限制

我是否遗漏了一些关于内存是如何使用的,以及为什么它会随机失效,但会处理更大的图像

我在同一个目录中有一个php.ini文件

memory_limit = 50M
post_max_size = 100M
file_uploads = On
upload_max_filesize = 192M
第34行:$this->image=imagecreatefromjpeg$filename

调整_calss.php的大小: 也要注意。用户一次最多上传3个图像,我正在循环使用这个类来调整和保存我服务器上的拇指
/*
* 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;
   }      

}
?>

您的脚本似乎已超出内存限制。52428800字节=50MB

您的脚本似乎已超出内存限制。52428800字节=50MB

图像重新大小将占用大量内存, 可以考虑使用InIsCub来提高内存限制。 特别是在resize_class.php中执行resize的方法

相关问题


图像重新大小将占用大量内存, 可以考虑使用InIsCub来提高内存限制。 特别是在resize_class.php中执行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方法中添加类似的内容

在我的示例中,我做了一件这件事,但这件事没有做,那就是在创建一个新图像后(例如在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方法中添加类似的内容


向我们展示resize_class.php中包含第34行的函数,然后人们可以尝试帮助您。我们应该如何调试看不见的代码您是否运行了xDebug跟踪以查看是什么占用了所有内存?也许你可以找到泄漏,这样你就可以保持在超过的50MB限制之下?很抱歉,请参阅上面关于第34行的编辑。我来看看xDebug@Denoteone我相信请求是针对包含第34行的整个函数/方法的。一行代码不会有多大帮助,但我猜,您并没有清理资源,每次使用时都会消耗更多内存imagecreatefromjpeg@Phil已添加完整的脚本。我还注意到,每次提交页面时,我都会循环使用脚本并多次使用该类。向我们展示resize_class.php中包含第34行的函数,然后人们可以尝试帮助您。我们应该如何调试看不见的代码您是否运行了xDebug跟踪以查看是什么占用了所有内存?也许你可以找到泄漏,这样你就可以保持在超过的50MB限制之下?很抱歉,请参阅上面关于第34行的编辑。我来看看xDebug@Denoteone我相信请求是针对包含第34行的整个函数/方法的。一行代码不会有多大帮助,但我猜,您并没有清理资源,每次使用时都会消耗更多内存imagecreatefromjpeg@Phil已添加完整的脚本。我还注意到,每次提交页面时,我都会循环使用脚本并多次使用该类answer@Phil…基于错误,我没有接近极限。这是对这一问题的第一次评论answer@Phil…基于错误,我没有接近极限。我现在就试试。谢谢你的反馈。我现在就试试。谢谢你的反馈。
function load($filename) {
    if (is_resource($this->image)) {
        imagedestroy($this->image);
    }

    // and the rest
}