ok, im lost,
so something like this?
PHP Code:
<?php
//Get the image
$image = $_GET['image'];
$cm = new bw($image);
// Get the dimensions
list($width, $height) = getimagesize($cm);
// This class turns a color image into Sepia
class bw {
var $_bw;
var $_type;
function printImage() {
switch ($this->_type) {
case IMAGETYPE_GIF : {
header('Content-Type: image/gif');
imagegif($this->_bw);
} break;
case IMAGETYPE_JPEG : {
header('Content-Type: image/jpeg');
imagejpeg($this->_bw);
} break;
case IMAGETYPE_PNG : {
header('Content-Type: image/png');
imagepng($this->_bw);
} break;
default : {
header('Content-Type: image/jpeg');
imagejpeg($this->_bw);
} break;
} // switch
imagedestroy($this->_bw);
}
function bw($path) {
// Let's find out what type is this image:
if (@is_file($path)) {
$this->_type = @exif_imagetype($path);
switch ($this->_type) {
case IMAGETYPE_GIF : {
$img = @imagecreatefromgif($path);
} break;
case IMAGETYPE_JPEG : {
$img = @imagecreatefromjpeg($path);
} break;
case IMAGETYPE_PNG : {
$img = @imagecreatefrompng($path);
} break;
default : {
$img =_errorImg();
} break;
} // switch ($this->_type)
// If image was created successfully, do some magic stuff
if ($img) {
$this->_bw = $this->_toBW($img);
imagedestroy($img);
} // if ($this->_img)
} // if (@is_file...)
else {
$this->_bw = $this->_errorImg();
}
}
function _errorImg() {
return imagecreate($width, $height);
}
function _toBW($src){
$x = imagesx($src);
$y = imagesy($src);
$dest = imagecreatetruecolor($x, $y);
for ($i=0;$i<$x;$i++) {
for ($j=0;$j<$y;$j++) {
$oldcolor = imagecolorsforindex($src, imagecolorat($src, $i, $j));
$newcolor = (int)(($oldcolor['red'] + $oldcolor['green'] + $oldcolor['blue']) / 3);
$sepia = array(
"red" => 145,
"green" => 65,
"blue" => 10
);
$mix = array(
"o" => 0.7,
"d" => 0.3
);
$newr = ($newcolor*$mix['o'] + $sepia['red']*$mix['d'])>255?255:($newcolor*$mix['o'] + $sepia['red']*$mix['d']);
$newg = ($newcolor*$mix['o'] + $sepia['green']*$mix['d'])>255?255:($newcolor*$mix['o'] + $sepia['green']*$mix['d']);
$newb = ($newcolor*$mix['o'] + $sepia['blue']*$mix['d'])>255?255:($newcolor*$mix['o'] + $sepia['blue']*$mix['d']);
imagesetpixel($dest, $i, $j, imagecolorallocate($dest, $newr, $newg, $newb ));
} // for($j
} // for ($i
return $dest;
}
}
import_request_variables('g','bw_');
$bw = new bw($bw_im);
$bw->printImage();
?>
Bookmarks