This example shows how to show black&white image in php gd.
This example shows how to show black&white image in php gd.<?php
$i = new imagethumbnail_blackandwhite(); $i->open("index.jpg");header(
"Content-type: image/jpeg;");}
}
}
}
function setY($y="") { if (isset($y)) { $this->y = $y; }}
function generate() {}
elseif ($this->x > 0 and $this->x != "") { $new_x = $this->x; $new_y = ($this->x/$this->old_x)*$this->old_y;}
else { $new_x = ($this->y/$this->old_y)*$this->old_x; $new_y = $this->y;}
$this->thumbnail = imagecreatetruecolor($new_x,$new_y); $white = imagecolorallocate($this->thumbnail,255,255,255);imagefill(
$this->thumbnail,0,0,$white);
imagecopyresampled (
$this->thumbnail, $this->image, 0, 0, 0, 0, $new_x, $new_y, $this->old_x, $this->old_y);}
function imagegif($filename="") { if (!isset($this->thumbnail)) { $this->generate(); }imagetruecolortopalette(
$this->thumbnail,0,256); if ($filename=="") {imagegif(
$this->thumbnail);}
else {imagegif(
$this->thumbnail,$filename);}
}
function imagejpeg($filename="",$quality=80) { if (!isset($this->thumbnail)) { $this->generate(); }imagejpeg(
$this->thumbnail,$filename,$quality);}
function imagepng($filename="") {imagepng(
$this->thumbnail);}
else {imagepng(
$this->thumbnail,$filename);}
}
}
class imagethumbnail_blackandwhite extends imagethumbnail {}
function blackandwhite() {}
for ($x=0;$x<imagesx($this->thumbnail);$x++) { for ($y=0;$y<imagesy($this->thumbnail);$y++) {imagesetpixel(
$this->thumbnail,$x,$y,$palette[$val]);}
}
}
}
?>
After running the program you will get the following output