Re: B/W Image

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ulrik Witschass wrote:
Hello List,

I browses the PHP Manual for some time now but didn't find exactly what I
was looking for.

I need to turn images uploaded by a user to b/w images to use them in
pdflib, the resulting PDF has to be black and white.

Now my question:

a) is this possible?

yes, it is.
if(a)

b) do I do this with PHP Image functions (maybe colorallicate and stuff like
that) or is it possible to actually do that in PDFLib?

I don't think it's doable using PDFLib, but you could write an implementation yourself. Here's one I just wipped up (so it might not work correctly).

<?php

$im = imagecreatefromWHATEVER($path);
$size = getimagesize($path);

$width = $size[0];
$height = $size[1];

$greyScaled = imagecreate($width, $height);
$pallet = array();

for($y=0;$y<$height;$y++) {
	for($x=0;$x<$width;$x++) {
	$index = imagecolorat($im, $x, $y);
		$rgba = imagecolorsforindex($im, $index);
		$newC = (($rgba['red']+$rgba['green']+$rgba['blue'])/3)
		if(!isset($pallet[$newC])) {
			$color = imagecolorallocate($greyScaled, $newC, $newC, $newC);
		} else {
			$color = $pallet[$newC];
		}
		imagesetpixel($greyScaled, $x, $y, $color);
	}
}

header('Content-type: image/png');

imagepng($greyScaled);
imagedestroy($im);
imagedestroy($greyScaled);
?>
thanks in advance for any help

Ulrik

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux