Imagick::writeImage

(PECL imagick 2 >= 2.3.0, PECL imagick 3)

Imagick::writeImage β€” ЗаписываСт ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ ΠΏΠΎ ΡƒΠΊΠ°Π·Π°Π½Π½ΠΎΠΌΡƒ ΠΈΠΌΠ΅Π½ΠΈ Ρ„Π°ΠΉΠ»Π°

ОписаниС

public function Imagick::writeImage(string $filename = NULL): bool

ЗаписываСт ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π² ΡƒΠΊΠ°Π·Π°Π½Π½ΠΎΠ΅ имя Ρ„Π°ΠΉΠ»Π°. Если ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ ΠΈΠΌΠ΅Π½ΠΈ Ρ„Π°ΠΉΠ»Π° Ρ€Π°Π²Π΅Π½ NULL, ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ записываСтся Π² имя Ρ„Π°ΠΉΠ»Π°, установлСнноС с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ Imagick::readImage() ΠΈΠ»ΠΈ Imagick::setImageFilename().

Бписок ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ²

filename

Имя Ρ„Π°ΠΉΠ»Π°, ΠΊΡƒΠ΄Π° Π·Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅. Π Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅ ΠΈΠΌΠ΅Π½ΠΈ Ρ„Π°ΠΉΠ»Π° опрСдСляСт Ρ‚ΠΈΠΏ Ρ„Π°ΠΉΠ»Π°. Π€ΠΎΡ€ΠΌΠ°Ρ‚ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΏΡ€ΠΈΠ½ΡƒΠ΄ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ установлСн нСзависимо ΠΎΡ‚ Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ Ρ„Π°ΠΉΠ»Π°, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡ прСфикс "format:" Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, "jpg:test.png".

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΡ‹Π΅ значСния

Ѐункция Π² случаС ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎΠΉ Ρ€Π°Π±ΠΎΡ‚Ρ‹ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ true.

οΌ‹Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ 4 notes

up
13
SkepticaLee ΒΆ
12 years 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.:

<?php
$im = new Imagick ();
$im->newImage (300, 225, "blue");
$im->writeImage ("test_0.jpg"); // fails with no error message
//instead
$im->setImageFormat ("jpeg");
file_put_contents ("test_1.jpg", $im); // works, or:
$im->imageWriteFile (fopen ("test_2.jpg", "wb")); //also works
?>
up
0
daniel at justathought dot dev ΒΆ
2 months ago
A list of supported image formats can be found in the ImageMagick documentation, here: https://imagemagick.org/script/formats.php#supported
up
0
icinagle at gmail dot com ΒΆ
15 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.
up
-1
pfz at pfzone dot org ΒΆ
13 years 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 : 

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

clearstatcache(dirname($your_file));
// or
unlink($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. 
<?php
file_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).