PHP Doku:: Sets the image compression quality - function.imagick-setimagecompressionquality.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzBildverarbeitung und -generierungImage Processing (ImageMagick)The Imagick classImagick::setImageCompressionQuality

Ein Service von Reinhard Neidl - Webprogrammierung.

The Imagick class

<<Imagick::setImageCompression

Imagick::setImageDelay>>

Imagick::setImageCompressionQuality

(No version information available, might only be in SVN)

Imagick::setImageCompressionQualitySets the image compression quality

Beschreibung

bool Imagick::setImageCompressionQuality ( int $quality )

Sets the image compression quality.

Parameter-Liste

quality

The image compression quality as an integer

Rückgabewerte

Liefert TRUE bei Erfolg.

Fehler/Exceptions

Wirft ImagickException bei Fehlern.


Ein BenutzerBeitrag:
- Beiträge aktualisieren...
snipes2083 [at] yahoo com
28.03.2010 21:35
This example shows how to set the compression type, set the compression quality, create a thumbnail and remove unnecessary data in order to reduce file size.

This will use the following functions in reference:
Imagick::setImageCompression
Imagick::setImageCompressionQuality
Imagick::stripImage
Imagick::thumbnailImage
Imagick::writeImage

<?php
    $image
= 'image.jpg';
   
$directory = '/path/to/image';
   
$image_location = $directory . "/" . $image;
   
$thumb_destination = $directory . "/t" . $image;
   
$compression_type = Imagick::COMPRESSION_JPEG;
  
   
$im = new Imagick($image_location);
   
$thumbnail = $im->clone;

   
$thumbnail->setImageCompression($compression_type);
   
$thumbnail->setImageCompressionQuality(40);
   
$thumbnail->stripImage();
   
$thumbnail->thumbnailImage(100,null);
   
$thumbnail->writeImage($thumb_destination);
?>

Now, obviously you don't have to do so much with the variables and the file location.  I only used so many to demonstrate where the images are coming from and where they are going.

NOTE:  The $thumbnail->thumbnailImage(100,null); keeps the aspect ration by setting the second parameter to null.  Read about this at Imagick::thumbnailImage

There is another way to create thumbnails that works quite well if you want to crop the image rather than using the entire image.  Check out Imagick::cropThumbnailImage



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)