views:

50

answers:

1

I'm workin on a script that list all images in one directory and then resize and save in another directory.

In my shared server, I receive this message:

Allowed memory size of 67108864 bytes exhausted (tried to allocate 600 bytes) in...

The question is: If PHP can free the memory after each image creation using image_destroy(), why the while loop that save these images get out of the memory limit?

--

The code just save the images, nothing more. The problem is with the amount of images, not with just one huge image. Each image have no more than 300KB and the script stop in the middle, and there isn't an exact point. Each time it's executed, it stop in some of the images.

foreach($images as $image) 
{
    $img = PhpThumbFactory::create($image);
    $img->adaptiveResize(640, 450);
    $img->createWatermark(PATH_TEMPLATE_SITE . 'img/watermark.png');
    $img->save($dirBig . $id . '.jpg','jpg');
}

The class used in this script is PHPThumb, and have the destructor:

public function __destruct ()
{
    if (is_resource($this->oldImage))
    {
        imagedestroy($this->oldImage);
    }

    if (is_resource($this->workingImage))
    {
        imagedestroy($this->workingImage);
    }
}

I alredy have the same issue saving images with other scripts. I think the problem isn't with this class, or other type of data used in the script.

A: 

The problem seems to be with the watermark plugin, that get an instance of the parentclass and put in a private member. I don't know exactly, but removing the private member and treating the parent class just as a parameter, the problem was solved.

I also have add a refresh after 20 images saved.

Keyne