note 78523 modified in function.imagejpeg by cmb
| From: | cmb@php.net | Date: | Tue, 04 Oct 2016 15:37:33 +0000 |
| Subject: | note 78523 modified in function.imagejpeg by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206756@lists.php.net to get a copy of this message | ||
[Editor's note: fixed according to the note of roberto at ilpiola.it]
I could not find any information on changing the DPI information on a JPG file using the GD lib.
Since changing this does not resize or scale the actual image, it is only a header-setting.
The following snipplet will save your $image to $file and set the DPI to 150.
<?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);
?>
P.s. not fully tested (yet) but it works for my images ...
--was--
I could not find any information on changing the DPI information on a JPG file using the GD lib.
Since changing this does not resize or scale the actual image, it is only a header-setting.
The following snipplet will save your $image to $file and set the DPI to 150.
<?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/255));
$image[15] = chr( $dpi_x%255);
$image[16] = chr(floor($dpi_y/255));
$image[17] = chr( $dpi_y%255);
// Write the new JPG
$f = fopen($file, 'w');
fwrite($f, $msg, $size);
fclose($f);
?>
P.s. not fully tested (yet) but it works for my images ...
http://php.net/manual/en/function.imagejpeg.php