note 21922 added to function.imagesetpixel
| From: | dino at nordmark dot dk | Date: | Fri, 31 May 2002 08:28:54 +0000 |
| Subject: | note 21922 added to function.imagesetpixel | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31265@lists.php.net to get a copy of this message | ||
The example above diden't work, because of some errors.
This should work and it's also faster because there is only one 512*512 loop. (but it is still
very slow)
<?
$filename="lena.raw";
$width=512;
$height=512;
$fp=fopen($filename, "r");
$contents=fread($fp,filesize($filename));
fclose($fp);
$image=imagecreate($width,$height);
// create greyscale palette because the image is limited to 256 colors
for ($i=0;$i<256;$i++){ ImageColorAllocate($image,$i,$i,$i);}
// This is slow, but probably the only way
for ($i=0;$i<512;$i++){
for ($j=0;$j<512;$j++){
imagesetpixel ($image,$i,$j,ord($contents[$i+$j*512]));
}
}
imagepng($image,"result.png");
imagedestroy($image);
echo "<img src=result.png></img>";
?>
--
Dino Patti
--
http://www.php.net/manual/en/function.imagesetpixel.php
http://master.php.net/manage/user-notes.php?action=edit+21922
http://master.php.net/manage/user-notes.php?action=delete+21922
http://master.php.net/manage/user-notes.php?action=reject+21922