convert's -density option

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
youds
Posts: 53
Joined: 2010-01-28T05:38:11-07:00
Authentication code: 8675309

convert's -density option

Post 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
ImageMagick 6.5.9-1
GhostScript 8.7
libpng-1.2.43RC1
iMagick 3.0.0RC1
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: convert's -density option

Post 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
Last edited by el_supremo on 2010-02-12T09:54:27-07:00, edited 1 time in total.
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
youds
Posts: 53
Joined: 2010-01-28T05:38:11-07:00
Authentication code: 8675309

Re: convert's -density option

Post 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
ImageMagick 6.5.9-1
GhostScript 8.7
libpng-1.2.43RC1
iMagick 3.0.0RC1
youds
Posts: 53
Joined: 2010-01-28T05:38:11-07:00
Authentication code: 8675309

Re: convert's -density option

Post 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();
ImageMagick 6.5.9-1
GhostScript 8.7
libpng-1.2.43RC1
iMagick 3.0.0RC1
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: convert's -density option

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
youds
Posts: 53
Joined: 2010-01-28T05:38:11-07:00
Authentication code: 8675309

Re: convert's -density option

Post 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.
ImageMagick 6.5.9-1
GhostScript 8.7
libpng-1.2.43RC1
iMagick 3.0.0RC1
youds
Posts: 53
Joined: 2010-01-28T05:38:11-07:00
Authentication code: 8675309

Re: convert's -density option

Post by youds »

This is really strange, same problem with 3.0.0b2.

The files are posted here, http://public.me.com/craigfairhurst
ImageMagick 6.5.9-1
GhostScript 8.7
libpng-1.2.43RC1
iMagick 3.0.0RC1
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: convert's -density option

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
youds
Posts: 53
Joined: 2010-01-28T05:38:11-07:00
Authentication code: 8675309

Re: convert's -density option

Post 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();
ImageMagick 6.5.9-1
GhostScript 8.7
libpng-1.2.43RC1
iMagick 3.0.0RC1
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: convert's -density option

Post by mkoppanen »

The following should work as well:

Code: Select all

$im = new Imagick();
$im->setResolution(360, 360);
$im->readImage('brookland.pdf');
Mikko Koppanen
My blog: http://valokuva.org
youds
Posts: 53
Joined: 2010-01-28T05:38:11-07:00
Authentication code: 8675309

Re: convert's -density option

Post by youds »

The two parameters there should be floats. Not sure why.
ImageMagick 6.5.9-1
GhostScript 8.7
libpng-1.2.43RC1
iMagick 3.0.0RC1
Post Reply