Rcrd 009
Rcrd 009

Reputation: 323

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.

Upvotes: 2

Views: 4164

Answers (2)

Sudharshan Nair
Sudharshan Nair

Reputation: 1267

First try this with Imagick

$image = new Imagick();
$image->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$image->setImageResolution(300,300);

If above doesn't work try this.

You can read file and convert DPI of image from 96 to 300. Try this.

  $imageGet = file_get_contents($imagePath);
  if($imageGet){
     $imageConverted = substr_replace($imageGet, pack("cnn", 1, 300, 300), 13, 5);
     $savefile = file_put_contents($newimagePath, $imageConverted);
  }

Upvotes: 0

David Bauer
David Bauer

Reputation: 399

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");

Upvotes: 1

Related Questions