Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

php imagejpeg() function allways set quality of 96 dpi

after uploading an image I place it in a folder using imagejpeg()
documentation says that this function resamples the image to a given quality, depending on third param in the function:

imagejpeg($newimg, $path, 80);

problem – whatever value I set as quality (50 – 70 – 99 …) the resulting image is always 96 dpi

so how to get an image having 72 dpi ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

DPI and quality are two completely different things.

The DPI is a piece of metadata that tells software how to scale the number of pixels in the image into inches. (This is generally only used when printing onto paper and in image editing software such as Photoshop; rendering the image on a website will work in pixels not inches).

The quality determines how much compression to use.


The imageresolution function lets you adjust the DPI metadata.

imageresolution($image, 72);

This comment, on the page you linked to, explains how to adjust the DPI setting manually.

<?php

  imagejpeg($image, $file, 75);

  // Change DPI
  $dpi_x   = 150;
  $dpi_y   = 150;
 
  // Read the file
  $size    = filesize($file);
  $image   = file_get_contents($file);

  // Update DPI information in the JPG header
  $image[13] = chr(1);
  $image[14] = chr(floor($dpi_x/256));
  $image[15] = chr(      $dpi_x%256);
  $image[16] = chr(floor($dpi_y/256));
  $image[17] = chr(      $dpi_y%256);

  // Write the new JPG
  $f = fopen($file, 'w');
  fwrite($f, $msg, $size);
  fclose($f);

?>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading