imagick filling /tmp

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
david222
Posts: 7
Joined: 2012-04-11T13:01:38-07:00
Authentication code: 8675308

imagick filling /tmp

Post by david222 »

hi all,

i'm new to imagick, got a big problem. one of the imagick routines seems to run amok, generating a huuuuuge temp file, and i have no idea why.

here's an example of what's happening-

Code: Select all

$ cd /tmp
$ ls -l magick-XXnifrbY
-rw------- 1 apache apache 70778880000 Apr 11 01:22 magick-XXnifrbY
i've dumped the first few megs of the file, nothing special [data] -- no headers, etc.
dumping farther in shows that the file sems to be 99.9% composed of 0's.
it seems like there's an imagick routine that's just running away...

is there any way to find out which method is causing this? maybe the file data has some of this information somewhere?

is the filename significant, i.e., can that be used to track down a process or file being worked on?

here's some supplemental info-
ImageMagick 6.5.4-7 2010-11-10 Q16 OpenMP http://www.imagemagick.org
imagick module version 3.0.1
x86_64 GNU/Linux 2.6.32-131.21.1.el6.x86_64

any help appreciated, the whole system frequently grinds to a halt because /tmp fills up.

thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: imagick filling /tmp

Post by fmw42 »

You probably should post your imagick script/commands so others can see how you are testing and getting such an error.

Also I believe that Imagick is at version 3.1.x. So you might want to upgrade both Imagemagick and Imagick.

Alternately, you can run imagemagick commands from PHP using the exec function. It is more flexible as Imagick is not supported very well to my knowledge and is not up-to-date with what you can do with Imagemagick.

see

http://www.rubblewebs.co.uk/index.php
david222
Posts: 7
Joined: 2012-04-11T13:01:38-07:00
Authentication code: 8675308

Re: imagick filling /tmp

Post by david222 »

it turns out the problem is being caused by resampleImage(). when attempting to resample images of a couple of megabytes at, e.g., 96dpi to 300dpi, it eats up all of the system's available memory, drives kswapd crazy, and eventually leaves a huge working file in /tmp, filling it up.

the routine that handles this is here:

Code: Select all

    try {
        $img = new Imagick($fnam);
        $img->setCompression(Imagick::COMPRESSION_JPEG);
        $img->setCompressionQuality(100);
        $img->setImageFormat('jpeg');
        $d = $img->getImageGeometry();
        $iw = $d["width"];
        $ih = $d["height"];
        $res = $img->getImageResolution();
        $resx = $res["x"];
        $resy = $res["y"];
        echo "original image dimensions: $iw x $ih<br>\n";//debug
        echo "original image resolution: $resx x $resy<br>\n";//debug
        if ($resx == 0 || $resy == 0)   // imagick failed
        {
            $err = "can't determine the resolution of this image. " .
                    "Unfortunately, you'll have to size it manually.";
            return null;
        }

        if ($iw == $resx * $x_vis) {
            echo "not resizing image<br>\n";//debug
        } else {
            echo utime()."\tresizing image to ".$resx * $x_vis."x".$resy * $y_vis.", ${resx}dpi<br>\n";//debug
            $changed = 1;
            $img->resizeImage($resx * $x_vis, $resy * $y_vis, imagick::FILTER_LANCZOS, 1);
        }
        if ($resx == DPI) {
            echo "not resampling image<br>\n";//debug
        } else {
            echo utime()."\tresampling image to ".DPI."dpi<br>\n";//debug
            $changed = 1;
            $img->setResolution(DPI, DPI);
            $img->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
            $img->resampleImage(DPI, DPI, imagick::FILTER_LANCZOS, 1);
        }
        $img->setImagePage(0,0,0,0);
        echo utime()."\twriting image<br>\n";//debug
        $img->writeImage($fnam);
        $img->destroy();
    }
    catch(Exception $e) {
        $err = "Can't resize/resample image $n. ".$e->getMessage().", line ".$e.getLine();
        return null;
    }
in the code snippet above, DPI is defined as 300.

am i doing something wrong here? is there a way i could do it better?

another problem is that getImageResolution() sometimes fails, returning 0. this is pretty flakey ; even windows knows how to get the resolution of an image.
david222
Posts: 7
Joined: 2012-04-11T13:01:38-07:00
Authentication code: 8675308

Re: imagick filling /tmp

Post by david222 »

anybody??
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: imagick filling /tmp

Post by Bonzo »

Imagick is not very well supported or documented, hardly anyone here uses it.

I belive it is not writen by the Imagemagick developers.
Post Reply