note 119133 added to function.imagejpeg
| From: | robertoatilpiola.it | Date: | Fri, 08 Apr 2016 06:52:44 +0000 |
| Subject: | note 119133 added to function.imagejpeg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205179@lists.php.net to get a copy of this message | ||
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);
?>
----
Server IP: 72.52.91.14
Probable Submitter: 194.153.187.147
----
Manual Page -- http://php.net/manual/en/function.imagejpeg.php
Edit -- https://master.php.net/note/edit/119133
Del: integrated -- https://master.php.net/note/delete/119133/integrated
Del: useless -- https://master.php.net/note/delete/119133/useless
Del: bad code -- https://master.php.net/note/delete/119133/bad+code
Del: spam -- https://master.php.net/note/delete/119133/spam
Del: non-english -- https://master.php.net/note/delete/119133/non-english
Del: in docs -- https://master.php.net/note/delete/119133/in+docs
Del: other reasons-- https://master.php.net/note/delete/119133
Reject -- https://master.php.net/note/reject/119133
Search -- https://master.php.net/manage/user-notes.php