note 108575 added to function.imagepng
| From: | paul at compusense dot nl | Date: | Tue, 08 May 2012 12:00:37 +0000 |
| Subject: | note 108575 added to function.imagepng | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187519@lists.php.net to get a copy of this message | ||
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);
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 194.121.28.162
----
Manual Page -- http://www.php.net/manual/en/function.imagepng.php
Edit -- https://master.php.net/note/edit/108575
Del: integrated -- https://master.php.net/note/delete/108575/integrated
Del: useless -- https://master.php.net/note/delete/108575/useless
Del: bad code -- https://master.php.net/note/delete/108575/bad+code
Del: spam -- https://master.php.net/note/delete/108575/spam
Del: non-english -- https://master.php.net/note/delete/108575/non-english
Del: in docs -- https://master.php.net/note/delete/108575/in+docs
Del: other reasons-- https://master.php.net/note/delete/108575
Reject -- https://master.php.net/note/reject/108575
Search -- https://master.php.net/manage/user-notes.php