05-03-1394، 07:45 ب.ظ
<?php header('Content-type: image/jpeg'); if(!isset($_GET['file']) || !file_exists($_GET['file']) || strtolower(substr($_GET['file'], strrpos($_GET['file'], '.'))) != '.jpg') { $im = imagecreatetruecolor(100, 100); $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); imagefill($im, 50, 50, $white); imagestring($im, 5, 30, 40, 'Error', $black); imagejpeg($im); imagedestroy($im); exit(); } $file = $_GET['file']; list($width, $height) = getimagesize($file); $source = imagecreatefromjpeg($file); $bwimage = imagecreate($width, $height); $palette = array(); for ($i = 0; $i < 256; $i++) { $palette[$i] = imagecolorallocate($bwimage, $i, $i, $i); } for($y = 0; $y < $height; $y++) { for($x = 0; $x < $width; $x++) { $color = imagecolorat($source, $x, $y); $r = ($color >> 16) & 0xFF; $g = ($color >> 8) & 0xFF; $b = ($color >> 0) & 0xFF; $gs = ($r * 0.299) + ($g * 0.587) + ($b * 0.114); imagesetpixel($bwimage, $x, $y, $palette[$gs]); } } imagejpeg($bwimage); imagedestroy($source); imagedestroy($bwimage); ?>