downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Imagick::setFilename> <Imagick::setCompression
Last updated: Fri, 20 May 2011

view this page in

Imagick::setCompressionQuality

(PECL imagick 0.9.10-0.9.9)

Imagick::setCompressionQualityEstablece la calidad de compresión predeterminda del objeto

Descripción

bool Imagick::setCompressionQuality ( int $quality )
Warning

Esta función no está documentada actualmente, solamente se encuentra disponible la lista de parámetros.

Establece la calidad de compresión predeterminda del objeto.

Parámetros

quality

Valores devueltos

Devuelve TRUE en caso de éxito.



Imagick::setFilename> <Imagick::setCompression
Last updated: Fri, 20 May 2011
 
add a note add a note User Contributed Notes Imagick::setCompressionQuality
charles dot hall at sas dot com 03-Aug-2010 06:31
I had to insert a call to "stripImage()" in order to actually see the filesize shrink.

<?php
   $img
= new Imagick();
  
$img->readImage($src);
  
$img->setImageCompression(imagick::COMPRESSION_JPEG);
  
$img->setImageCompressionQuality(90);
  
$img->stripImage();
  
$img->writeImage($dest);
?>
deeps chennai 18-Mar-2010 10:59
A note for people who just couldn't get this working..

With PHP 5.1.6, the below works:

<?php
$img
->setCompression(Imagick::COMPRESSION_JPEG);
$img->setCompressionQuality(80);
?>

However, with higher versions of PHP (I tried on PHP 5.2.10), the code has no effect (and there are no exceptions or warnings thrown by Imagick as well).

The code that works instead is:

<?php
$img
->setImageCompression(Imagick::COMPRESSION_JPEG);
$img->setImageCompressionQuality(80);
?>

and this is backwards compatible (Works on PHP 5.1.6 as well as 5.2.10)
nVaux.com 27-Mar-2008 04:24
Sebastian's example works excellent, just one minor spelling mistake, it will give you an error otherwise.

<?php
$img
->setCompression(Imagick::COMPRESSION_JPEG);
$img->setCompressionQuality(80);
?>

I used Sebastians example, and made one that compresses all the images within a directory:

<?php
$images
= new Imagick(glob('images/*.jpg'));

foreach(
$images as $image)
{
   
// compression methods, see "Contants"-page for Imagick
   
$image->setCompression(imagick::COMPRESSION_JPEG);
   
// a value between 1 and 100, 1 = high compression, 100 low compression
   
$image->setCompressionQuality(80);
   
$image->writeImage();
}

?>
sebastian dot moser at gmail dot com 17-Nov-2007 10:46
Use this example to see how image compression works:

<?php
// load an image
$img = new Imagick("test.jpg");

// compression methods, see "Contants"-page for Imagick
$img->setComression(Imagick::COMPRESSION_JPEG);
// a value between 1 and 100, 1 = high compression, 100 low compression
$img->setComressionQuality(80);

// set content type
header("Content-type: image/jpeg");
// write image
echo $img->getImageBlob();
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites