Return Values

User Contributed Notes 4 notes

When running Imagick as packaged with the Abyss Web Server, neither this method nor writeImages () works. Instead the format has to be declared and the file saved by using another method or procedure, e.g.:

With Imagick 3.1.0RC2, PHP4.8If you plan to overwrite the file you're working on, before doing writeImage, consider clearing the file buffer before the write statement :

<?php$image = new Imagick($your_file);/* some processing */

clearstatcache(dirname($your_file));// orunlink($your_file);$image->writeImage($your_file);?>It happened to me that the resulting file size was wrong. This could lead to truncation, as the file is not expanded.This happened while working on JPEG, and PNG.

this line worked for me without this hack. <?phpfile_put_contents($your_file, $image);?>

Do not rely on getImageLength() for sending your image, especially when keepalive is ON. Content length is then relevant, and must be set. If the wrong size is given, your image will be truncated.Use filesize($your_file_) once written or strlen($image) instead (which renders your image and updates getImageLength() result).

If you are trying to manipulate a uploaded file and then save the file all in the same request with Apache + mod_dav this will fail.mod_dav puts a lock on the file during the request where the file is uploaded so trying to save the smallest file, e.g. 1kb will fail with a "Failed to allocate memory" error.