Types of Read images
1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF (Intel byte order), 8 = TIFF (Motorola byte order), 9 = JPC , ten = JP2, one = JPX, one = JB2, and the SWC, = IFF
function Getimagetype ($filename) {return ($imginfo = @getimagesize ($filename))!=null? $imginfo [2]: null);}
Image Sharpening
$SCR _im: Image resource handle, $degree: Sharpening degrees
Function Sharp (& $SRC _im, & $dst _im, $degree)
{
$src _x = imagesx ($src _im);
$src _y = Imagesy ($src _im);
$DST _im = imagecreate ($src _x, $src _y);
Imagecopy ($dst _im, $src _im, 0, 0, 0, 0, $src _x, $src _y);
$cnt = 0;
for ($x =1; $x < $src _x; $x + +)
for ($y =1; $y < $src _y; $y + +)
{
$src _CLR1 = Imagecolorsforindex ($src _im, Imagecolorat ($src _im, $x-1, $y-1));
$src _CLR2 = Imagecolorsforindex ($src _im, Imagecolorat ($src _im, $x, $y));
$r = intval ($src _clr2["Red"]+ $degree * ($src _clr2["Red"-$src _clr1["Red"]));
$g = intval ($src _clr2["green"]+ $degree * ($src _clr2["green"]-$src _clr1["green"));
$b = intval ($src _clr2["Blue"]+ $degree * ($src _clr2["Blue"-$src _clr1["Blue"]));
$r = min (255, max ($r, 0));
$g = min (255, max ($g, 0));
$b = min (255, max ($b, 0));
echo "R: $r, G: $g, B: $b
";
if ($dst _clr=imagecolorexact ($dst _im, $r, $g, $b)) ==-1)
$DST _clr = imagecolorallocate ($dst _im, $r, $g, $b);
$cnt + +;
if ($dst _clr==-1) die ("Color allocate faile at $x, $y ($cnt).");
Imagesetpixel ($dst _im, $x, $y, $dst _clr);
}
return $DST _im;
}
$ImageFunctions = Array ("Imagecreatefromwbmp", "Imagecreatefromgif", "Imagecreatefromjpeg", "imagecreatefrompng");
if (!empty ($_post["ImageName"))
{
Set_time_limit (10*60);
if (($ImageType =getimagetype ($_post["ImageName")) ==false)
Die ("The specified file does not exist or is not a valid picture or unsupported type!") ");
if ($ImageType ==6) $ImageType = 0;
if ($ImageType >3) die ("Unsupported picture Type! ");
$im 1 = $ImageFunctions [$ImageType] ($_post["ImageName"]);
$im 2 = $ImageFunctions [$ImageType] ($_post["ImageName"]);
Print_r (Imagecolorsforindex ($im, Imagecolorat ($im, 10, 10));
Sharp ($im 1, $im 2, $_post["degree"]);
Header ("Content-type:image/png");
Imagepng ($im 2);
Imagedestroy ($im 1);
Imagedestroy ($im 2);
}
?>
Changed a bit, save a $im:
Function Sharp2 (& $im, $degree)
{
$cnt = 0;
For ($x =imagesx ($im)-1; $x >0; $x-)
For ($y =imagesy ($im)-1; $y >0; $y-)
{
$CLR 1 = imagecolorsforindex ($im, Imagecolorat ($im, $x-1, $y-1));
$CLR 2 = Imagecolorsforindex ($im, Imagecolorat ($im, $x, $y));
$r = intval ($clr 2["Red"]+ $degree * ($clr 2["Red"-$clr 1["Red"]));
$g = intval ($clr 2["green"]+ $degree * ($clr 2["green"]-$clr 1["green"));
$b = intval ($clr 2["Blue"]+ $degree * ($clr 2["Blue"-$clr 1["Blue"]));
$r = min (255, max ($r, 0));
$g = min (255, max ($g, 0));
$b = min (255, max ($b, 0));
echo "R: $r, G: $g, B: $b
";
if ($new _clr=imagecolorexact ($im, $r, $g, $b)) ==-1)
$new _clr = imagecolorallocate ($im, $r, $g, $b);
$cnt + +;
if ($new _clr==-1) die ("Color allocate faile at $x, $y ($cnt).");
Imagesetpixel ($im, $x, $y, $new _clr);
}
}
http://www.bkjia.com/PHPjc/314463.html www.bkjia.com true http://www.bkjia.com/PHPjc/314463.html techarticle ?//Read the type of image//1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF (Intel byte order), 8 = TIFF (Motorola Byte Order), 9 = JPC, ten = JP2, one = JPX, one = JB2,...