note 21168 deleted from function.imagesetpixel by didou
| From: | didou@php.net | Date: | Wed, 18 Aug 2004 13:17:17 +0000 |
| Subject: | note 21168 deleted from function.imagesetpixel by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74880@lists.php.net to get a copy of this message | ||
Note Submitter: mailbox at mail dot kghs dot net
----
Create an PNG file from RAW use imagesetpixel
---------------------------------------------
download "lena.raw" first
http://gatekeeper.dec.com/pub/X11-contrib/wavelet_pic/lena.raw
which is a 512*512 raw image file.
<?
$filename="lena.raw";
$width=512;
$height=512;
$fp=fopen($filename, "r");
$contents=fread($fp,filesize($filename));
fclose($fp);
$contents=chunk_split("$contents",8,",");
for ($i=0;$i<512;$i++){
for ($j=0;$j<512;$j++){
$img[$i][$j]=base_convert(bin2hex($contents[$i+$j]),16,10);
}
}
$image=imagecreate($width,$height);
for ($i=0;$i<512;$i++){
for ($j=0;$j<512;$j++){
imagesetpixel ($image,$i,$j,$color[$i][$j]);
}
}
imagepng($image,"result.png");
imagedestroy($image);
echo "<img src=result.png></img>";
?>
--
Ming Zhi Huang. - Taiwan