Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3311146
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:50:33+00:00 2026-05-17T21:50:33+00:00

I am trying batch resize a bunch of images (~220). I am getting: (everytime)

  • 0

I am trying batch resize a bunch of images (~220). I am getting: (everytime)

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19520 bytes) in C:\xampp\htdocs\jason\inc\admin\image.resize.functions.php on line 31

I get the error at the same point EVERY TIME, regardless of how many times I call $n->resizeToHeight($c). It will cycle through about 100 photos then crash as soon as I try to resize ONE. Or I can resize 100 photos and it will crash on the 101st. I can even go through all cases of switch($k) (cause it resize 300 photos), and it will still crash after the 101st instance of the class Image.

Does my explanation of the error make sense? I am throwing around “100”, it may not necessarily be 100, could be 75, or 125 (don’t know the exact number). It just consistently crashes at the same spot.

Should be noted: I am testing with XAMPP. I haven’t tried it in a real environment (because I can’t yet).

resize-images.php (what is necessary)

    foreach($imgs as $img){
        $i = new Image($img['cid']);
        foreach($go as $k=>$c){
            if($i->$k > $c+IMGTOL || $i->$k < $c-IMGTOL) {
                $n = new SimpleImage();
                $n->load(ORIGABSLOC."/".$i->filename);
                $n->resizeToHeight($c);
                switch($k){
                    case "image_height":
                        $loc = IMGABSLOC;
                        break;
                    case "thumb_height":
                        $loc = THUMBABSLOC;
                        break;
                    case "mobile_height":
                        $loc = MOBILEABSLOC;
                        break;
                }
                $n->save($loc."/".$i->filename);
                $n->destroy();
                unset($n);
            }
            echo "<style>#$k-$count{background-color:blue;}</style>";
            flush_();
        }
        $count++;
        unset($i);
    }

I echo the <style> and flush_() it so I get a loading bar effect. Doesn’t matter if I flush or not, still crashes at the same spot.

Image class (what is necessary)

class Image{
function Image($id){
    $img = selectImages(array('type'=>4,'id'=>$id));
    if(sizeof($img) < 1) {
        return NULL;
    }
    if(sizeof($img)>0){
        foreach($img[0] as $k=>$c){
            if(!is_numeric($k)) {
                $this->$k = $c;
            }
        }
        $this->type = $this->display_type;
        $size = @getimagesize(IMGABSLOC."/".$this->filename);
        $this->height = $size[1];
        $this->width = $size[0];
        $this->image_height = $size[1];
        $this->image_width = $size[0];
        $size = @getimagesize(ORIGABSIMGLOC."/".$this->filename);
        $this->original_height = $size[1];
        $this->original_width = $size[0];
        $size = @getimagesize(THUMBABSLOC."/".$this->filename);
        $this->thumb_height = $size[1];
        $this->thumb_width = $size[0];
        $size = @getimagesize(MOBILEABSLOC."/".$this->filename);
        $this->mobile_height = $size[1];
        $this->mobile_width = $size[0];
        $this->anchor = $this->album;
    }
    else return false;
}

SimpleImage Class (what is necessary)

    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 resizeToHeight($height) {
      $ratio = $height / $this->getHeight();
      $width = $this->getWidth() * $ratio;
      $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());
      imagedestroy($this->image);
      $this->image = $new_image;   
   }
   function destroy(){
    imagedestroy($this->image);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:50:34+00:00Added an answer on May 17, 2026 at 9:50 pm

    Fixed. Appears as though it didn’t like some images.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to batch convert a bunch of assorted iWork files (Numbers, Pages, Keynote)
I'm trying to convert a batch of .ICO images over to .PNG images in
Trying to set some basic validation in a batch file but keep getting a
When trying to do an HQL batch update for Order entity, I'm getting the
I'm trying to execute a batch file in C#, but I'm not getting any
I'm trying to execute a batch file to move a bunch of files around
I am trying to batch rename several files that are named using the following
I am trying to use batch updates in Access VBA. My code works fine
I am trying to do batch insert with GORM and I try to clear
I am trying to iterate a string in batch script: set var=1 2 3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.