Reply to Re: WBMP output doesn't work

Your name:

Reply:


Posted by Janwillem Borleffs on 08/06/05 15:40

AaronV wrote:
> Replacing the imagewbmp with imagejpeg will output a valid jpeg file,
> or I can output a valid PNG as well. But outputing a wbmp never works,
> I get a busted image. Anyone know what's going on here? Am I missing
> some color conversion step?

The problem is that WBMP can only be created from images which contain black
and white only.

The imagetruecolortopalette() function seems to be able to reduce the color
depth, but the result will still be insufficient to create a WBMP image,
because it will not consist of just black and white.

One solution is to map the pixels to either black or white manually. You
will need to to this after you have resampled the image and before you call
imagewbmp().

The following code produced reasonable results with the images I have tested
it with:

for ($y = 0; $y < $new_height; $y++) {
for ($x = 0; $x < $new_width; $x++) {
$colors = imagecolorsforindex(
$image_p,
imagecolorat($image_p, $x, $y)
);

if ($colors['red'] > 180) {
$color = imagecolorallocate($image_p, 255, 255, 255);
} else {
$color = imagecolorallocate($image_p, 0, 0, 0);
}
imagesetpixel($image_p, $x, $y, $color);
}
}

As I said, you should insert this code just after you have called
imagecopyresampled() and before calling imagewbmp().


HTH;
JW

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация