(PECL imagick 0.9.0-0.9.9)

Imagick::writeImageWrites an image to the specified filename


bool Imagick::writeImage ([ string $filename = NULL ] )

Writes an image to the specified filename. If the filename parameter is NULL, the image is written to the filename set by Imagick::readImage() or Imagick::setImageFilename().



Filename where to write the image. The extension of the filename defines the type of the file. Format can be forced regardless of file extension using format: prefix, for example "jpg:test.png".

Valorile întoarse

Întoarce TRUE în caz de succes.

add a note add a note

User Contributed Notes 3 notes

22 days ago
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.:

= new Imagick ();
$im->newImage (300, 225, "blue");
$im->writeImage ("test_0.jpg"); // fails with no error message
$im->setImageFormat ("jpeg");
file_put_contents ("test_1.jpg", $im); // works, or:
$im->imageWriteFile (fopen ("test_2.jpg", "wb")); //also works
pfz at pfzone dot org
1 year ago
With Imagick 3.1.0RC2, PHP4.8
If you plan to overwrite the file you're working on, before doing writeImage, consider clearing the file buffer before the write statement :

= new Imagick($your_file);
/* some processing */

// or
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.
($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).
icinagle at gmail dot com
2 years ago
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.
To Top