php 浏览器输出图片大小,PHP 以 WBMP 格式将图像输出到浏览器或文件

andre at bynetworld dot com (2007-12-19 05:31:43)

In the previous note by -> lukeross at sys3175 dot co dot uk

The following is the corrected function code:

function ImageColorFloydSteinberg($dst_img, $src_img) {

ImageColorAllocate($dst_img, 0,0,0);

ImageColorAllocate($dst_img, 255,255,255);

$isx = ImageSX($src_img);

$isy = ImageSY($src_img);

$grey_img = ImageCreate($isx, $isy);

for ($a = 0; $a <= 255; $a++) ImageColorAllocate($grey_img, $a,$a,$a);

$isx -= 1; // To correct pixel count in source image width starting from 0

$isy -= 1; // Correcting pixel count in source image height starting from 0

for($x = 0; $x <= $isx; $x++) {

for($y = 0; $y <= $isy; $y++) {

$color = ImageColorsForIndex($src_img, ImageColorAt($src_img, $x, $y));

$greyscale = .299 * $color["red"] + .587 * $color["green"] + .114 * $color["blue"];

ImageSetPixel($grey_img, $x, $y, ImageColorClosest($grey_img, $greyscale, $greyscale, $greyscale));

}

}

for($x = 0; $x <= $isx; $x++) {

for($y = 0; $y <= $isy; $y++) {

$color = ImageColorsForIndex($grey_img, ImageColorAt($grey_img, $x, $y));

if ($color["red"] > 128) {

ImageSetPixel($dst_img, $x, $y, ImageColorClosest($dst_img,255,255,255));

$err = $color["red"] - 255;

} else {

ImageSetPixel($dst_img, $x, $y, ImageColorClosest($dst_img,0,0,0));

$err = $color["red"];

}

if ($x != $isx) {

$color2 = ImageColorsForIndex($grey_img, ImageColorAt($grey_img, $x+1, $y));

$newgrey = $color2["red"] + $err * 7 / 16;

ImageSetPixel($grey_img, $x+1, $y, ImageColorClosest($grey_img,$newgrey, $newgrey, $newgrey));

}

if ($x != 0) {

$color2 = ImageColorsForIndex($grey_img, ImageColorAt($grey_img, $x-1, $y));

$newgrey = $color2["red"] + $err * 3 / 16;

ImageSetPixel($grey_img, $x-1, $y, ImageColorClosest($grey_img,$newgrey, $newgrey, $newgrey));

}

if ($y != $isy) {

$color2 = ImageColorsForIndex($grey_img, ImageColorAt($grey_img, $x, $y+1));

$newgrey = $color2["red"] + $err * 5 / 16;

ImageSetPixel($grey_img, $x, $y+1, ImageColorClosest($grey_img,$newgrey, $newgrey, $newgrey));

}

if ($x != $isx && $y != $isy) {

$color2 = ImageColorsForIndex($grey_img, ImageColorAt($grey_img, $x+1, $y+1));

$newgrey = $color2["red"] + $err / 16;

ImageSetPixel($grey_img, $x+1, $y+1, ImageColorClosest($grey_img,$newgrey, $newgrey, $newgrey));

}

}

}

imagedestroy($grey_img);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值