note 119133 deleted from function.imagejpeg by cmb
| From: | cmb@php.net | Date: | Tue, 04 Oct 2016 15:37:42 +0000 |
| Subject: | note 119133 deleted from function.imagejpeg by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206757@lists.php.net to get a copy of this message | ||
Note Submitter: roberto at ilpiola.it
----
I really appreciated Michaelsoft's method for setting the DPI, but it is perfect only for low
DPI values.
When I tried to set the DPI to 300 (for a printer-ready image), I really got a 301 DPI image. the
correct code should have 256 instead of 256 as the divisor:
<?
// Change DPI, from http://php.net/manual/it/function.imagejpeg.php#78523
$dpi_x = 300;
$dpi_y = 300;
// Read the file
$size = filesize($argv[11]);
$image = file_get_contents($argv[11]);
// 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($argv[11], 'w');
fwrite($f, $image, $size);
fclose($f);
?>