Code sưu tầm được, bạn đưa code vào cùng với thư mục ảnh của bạn đặt tên là index.php nhé
[quote]
<?php
$direction = 'H';
$dim = true;
$text = 'www.techshopvn.com';
$font = 2;
error_reporting(0);
$filename = $_SERVER['QUERY_STRING'];
$size = GetImageSize ($filename);
switch ($size[2])
{
case 2:
Header('Content-type: image/jpeg');
$funcCreate = 'ImageCreateFromJpeg';
$funcOutput = 'ImageJpeg';
break;
case 3:
Header('Content-type: image/png');
$funcCreate = 'ImageCreateFromPng';
$funcOutput = 'ImagePng';
break;
default:
Header ('Content-type: image/gif');
if (! @readfile($filename))
{
$error = ImageCreate(100,40);
$c_grey = ImageColorAllocate($error, 128, 128, 128);
$c_white = ImageColorAllocate($error, 255, 255, 255);
ImageFill($error, 0, 0, $c_grey);
Imagestring($error, 5, 1, 12, 'Image error', $c_white);
echo ImagePng($error);
ImageDestroy($error);
return;
}
}
$width = ImageFontWidth($font)*strlen($text);
$height = ImageFontHeight($font);
$image = $funcCreate($filename);
if ($direction=='H')
{
get_color($size[0]-$width-5, $size[1]-$height-5, $size[0]-5, $size[1]-5);
ImageString($image, $font, $size[0]-$width-4, $size[1]-$height-4, $text, $color_bg);
ImageString($image, $font, $size[0]-$width-5, $size[1]-$height-5, $text, $color);
}
else
{
get_color($size[0]-$height-5, $size[1]-$width-5, $size[0]-5, $size[1]-5);
ImageStringUp($image, $font, $size[0]-$height-4, $size[1]-6, $text, $color_bg);
ImageStringUp($image, $font, $size[0]-$height-5, $size[1]-5, $text, $color);
}
echo $funcOutput($image);
ImageDestroy($image);
function get_color($x1, $y1, $x2, $y2)
{
global $image, $dim, $color, $color_bg;
if (!$dim)
{
$color = ImageColorAllocate($image, 0, 255, 255);
$color_bg = ImageColorAllocate($image, 255, 0, 255);
return;
}
for($x = $x1; $x <= $x2; $x++)
{
for ($y = $y1; $y <= $y2; $y++)
{
$colors = ImageColorsForIndex($image, ImageColorAt($image, $x, $y));
$text_color['r'] += $colors['red']; $text_color['r'] /= 2;
$text_color['g'] += $colors['green']; $text_color['g'] /= 2;
$text_color['b'] += $colors['blue']; $text_color['b'] /= 2;
}
}
$text_color['r'] = $text_color['r'] < 128 ? $text_color['r'] + 128 : $text_color['r'] - 128;
$text_color['g'] = $text_color['g'] < 128 ? $text_color['g'] + 128 : $text_color['g'] - 128;
$text_color['r'] = $text_color['r'] < 128 ? $text_color['r'] + 128 : $text_color['r'] - 128;
$color = ImageColorAllocate($image, $text_color['r'], $text_color['g'], $text_color['b']);
$color_bg = ImageColorAllocate($image,
($text_color['r'] > 128 ? 10 : 240),
($text_color['g'] > 128 ? 10 : 240),
($text_color['b'] > 128 ? 10 : 240));
}
php>[/quote]
Sau đó bạn sửa lại trong lệnh gọi ảnh của bạn, thí dụ như lệnh gọi ảnh bình thường là:
[red]<img src=\"images/star.jpg\"> [/red]
Giờ bạn thay vào là [red]<img src=\"images/?star.jpg\">[/red]