Page 1 of 1

convert's -density option

Posted: 2010-02-12T05:22:36-07:00
by youds
Hi

Quick question

What is the equivalent "-density" option for Imagick?

There appears to be no apparent option to set the density for an image conversion, only Imagick::getImageTotalInkDensity.

Here's my code:

Code: Select all

$im = new Imagick('file.pdf'); 
$im->setImageColorspace(255);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(100);
$im->setImageFormat('jpeg');
$output = $im->getimageblob();
$outputtype = $im->getFormat();
header("Content-type: $outputtype");
echo $output;
$im->clear();
$im->destroy();
The command I'm using at CLI is: convert -density 360 file.pdf file.jpg
Also, the background changes from white to pink with Imagick code above (but not at CLI), do you need to set additional properties to keep the background colour the same?

Kind regards

Re: convert's -density option

Posted: 2010-02-12T08:31:59-07:00
by el_supremo
In C it would be:

Code: Select all

MagickSetImageOption(magick_wand,"density","360");
Pete
[edit] fixed the type of the third argument

Re: convert's -density option

Posted: 2010-02-12T08:46:20-07:00
by youds
Thanks for the reply.

From going through the list based on what you said, I found: http://uk3.php.net/manual/en/function.i ... lution.php

A user comment says this is the density option.

Kind regards

Re: convert's -density option

Posted: 2010-02-12T09:33:35-07:00
by youds
Doesn't appear to do anything. Image quality stays the same no matter what you put for the values.

Tested with both iMagick 2.3.0 and iMagick 3.0.0b2

Here's my code:

Code: Select all

$im = new Imagick('flyer-from-illustrator.pdf'); 
$im->setImageResolution(360, 360);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(100);
$im->setImageFormat('jpeg');
$output = $im->getimageblob();
$outputtype = $im->getFormat();
header("Content-type: $outputtype");
echo $output;
$im->clear();
$im->destroy();

Re: convert's -density option

Posted: 2010-02-12T09:53:29-07:00
by el_supremo
Try this page http://php.net/manual/en/function.imagick-setoption.php

And a correction. The third argument is a string:

Code: Select all

MagickSetImageOption(magick_wand,"density","360");
Pete

Re: convert's -density option

Posted: 2010-02-12T10:04:51-07:00
by youds
Thanks for the replies Pete.

I'm struggling to find a solution, I've tried the below with no joy.

Code: Select all

$im->setImageResolution(360.00, 360.00);
$im->setOption('density', '360');
Currently using Imagick 2.3.0, upgrading to 3.0.0b2 to test with that as well at the moment - not holding out much hope though.

Re: convert's -density option

Posted: 2010-02-12T10:15:28-07:00
by youds
This is really strange, same problem with 3.0.0b2.

The files are posted here, http://public.me.com/craigfairhurst

Re: convert's -density option

Posted: 2010-02-12T10:26:48-07:00
by el_supremo
I don't know how to use IMagick but what you need to do is instantiate the $im object without reading the image. Set the density and then read in the image. This will then do things in the same order as the command line which sets the density before the image is read in.
I'm guessing at the syntax but you need something like this:

Code: Select all

$im = new Imagick(); 
$im->setOption('density', '360');
$im->Read('flyer-from-illustrator.pdf');
Pete

Re: convert's -density option

Posted: 2010-02-12T10:32:46-07:00
by youds
That worked, thank you!

The final solution was as follows:

Code: Select all

$im = new Imagick(); 
$im->setOption('density', '360');
$im->readImage('brookland.pdf');
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(100);
$im->setImageFormat('jpeg');
$output = $im->getimageblob();
$outputtype = $im->getFormat();
header("Content-type: $outputtype");
echo $output;
$im->clear();
$im->destroy();

Re: convert's -density option

Posted: 2010-02-13T19:52:08-07:00
by mkoppanen
The following should work as well:

Code: Select all

$im = new Imagick();
$im->setResolution(360, 360);
$im->readImage('brookland.pdf');

Re: convert's -density option

Posted: 2010-02-14T07:28:14-07:00
by youds
The two parameters there should be floats. Not sure why.