note 108575 deleted from function.imagepng by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 16:43:23 +0000 |
| Subject: | note 108575 deleted from function.imagepng by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187584@lists.php.net to get a copy of this message | ||
Note Submitter: paul at compusense dot nl
----
Based on Matt's code for IE6 compatibility I made a function that adds a DPI header to a PNG
file.
<?php
function changePngDpi($filename, $x_dpi = 150, $y_dpi = 150) {
$pngData = bin2hex(file_get_contents($filename));
$idatMarker = '200049444154';
$physMarker = '70485973';
$physChunk = '0009'.$physMarker;
$dpiData = array(
$x_dpi / 0.0254,
$y_dpi / 0.0254
);
$physChunkData = '';
foreach ($dpiData as $data) {
$physChunkData .= str_pad(dechex($data), 8, '0', STR_PAD_LEFT);
}
// Specify unit to meters
$physChunkData .= '01';
$physChunk .= $physChunkData;
$physChunk .= dechex(crc32(pack('H*', $physMarker .
$physChunkData))).'0000';
$parsed = explode($idatMarker, $pngData, 2); // split file by first 'IDAT' chunk
$pngData = pack('H*', $parsed[0] . $physChunk . $idatMarker . $parsed[1]);
file_put_contents($filename, $pngData);
}
?>