Search code examples
phpimagemagickdpi

Change in dpi using imagick library in php


We are adding some text using annotateimage function using imagick library in php. Source file is in 300 dpi, but after editing, output file becomes 96 dpi.

How can we fix it?

EDIT******************************

When we try this in our local development server, output file is also showing at 300 dpi. This issue is coming only when we test this in our web server. Both are linux and Imagick versions are also same.


Solution

  • You can use setResolution for this, as an equivalent to the -density commandline switch.

    http://php.net/manual/en/function.imagick-setresolution.php

    Edit:

    You have to set this before reading the image for this to work.

    $im = new Imagick(); 
    $im->setResolution(300,300); 
    $im->readImage("image.jpg");