php[world] 2019 — 25 years of PHP

Imagick::setImageCompression

(PECL imagick 2.0.0)

Imagick::setImageCompression画像の圧縮を設定する

説明

Imagick::setImageCompression ( int $compression ) : bool

画像の圧縮を設定します。

パラメータ

compression

COMPRESSION 定数のいずれか。

返り値

成功した場合に TRUE を返します。

エラー / 例外

エラー時に ImagickException をスローします。

add a note add a note

User Contributed Notes 2 notes

up
7
snipes2083 [at] yahoo com
9 years ago
Above it says "One of the COMPRESSION constants" for the parameters.  For any of you that found this confusing, you can find a list of the constants here:

Predefined Constants
http://www.php.net/manual/en/imagick.constants.php

As an example for working with a jpeg image:

<?php
    $image
= 'jpeg_image.jpg';
   
$comression_type = Imagick::COMPRESSION_JPEG;
   
   
$im = new Imagick($image);
   
$im->setImageCompression($compression_type);
?>

This class does not actually compress the images but rather sets the compression type that is going to be used. 

If you would like to see how to compress the image see:
Imagick::setImageCompressionQuality
up
0
jacob at fragdev dot com
3 months ago
On Ubuntu 18.04, these are the default compression methods used for the following common image formats:

PNG:  Imagick::COMPRESSION_ZIP
JPEG: Imagick::COMPRESSION_JPEG
GIF:  Imagick::COMPRESSION_LZW
To Top