1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| function create_watermark($imgfile) {
if (function_exists("imagecreate")) {
$imginfo = @getimagesize($imgfile);
// start 1
$samtext = "сайт.ru";
$font_name = "NewtonC.ttf";
$font_height = 16;
$font_x = $imginfo[0] - 130;
$font_y = 25;
$imgthumb = $imgfile;
// end 1
switch($imginfo[2]) {
case 1:
$type = IMG_GIF;
break;
case 2:
$type = IMG_JPG;
break;
case 3:
$type = IMG_PNG;
break;
case 4:
$type = IMG_WBMP;
break;
default:
// return $imgfile;
break;
}
switch($type) {
case IMG_GIF:
if (!function_exists("imagecreatefromgif")) return $imgfile;
$srcImage = @imagecreatefromgif("$imgfile");
break;
case IMG_JPG:
if (!function_exists("imagecreatefromjpeg")) return $imgfile;
$srcImage = @ImageCreateFromJpeg($imgfile);
break;
case IMG_PNG:
if(!function_exists("imagecreatefrompng")) return $imgfile;
$srcImage = @imagecreatefrompng("$imgfile");
break;
case IMG_WBMP:
if (!function_exists("imagecreatefromwbmp")) return $imgfile;
$srcImage = @imagecreatefromwbmp("$imgfile");
break;
default:
// return $imgfile;
}
if ($srcImage){
$srcWidth = $imginfo[0];
$srcHeight = $imginfo[1];
$ratioWidth = $srcWidth;
$destWidth = $imginfo[0];
$destHeight = $imginfo[1];
$destImage = @imagecreatetruecolor($destWidth, $destHeight);
@imagealphablending($destImage, true);
@imagealphablending($srcImage, false);
// @imagecopyresized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
@imagecopy($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight);
$text_color = @ImageColorAllocate($destImage, 0, 0, 0);
@imagettftext($destImage, $font_height, 0, $font_x, ($font_y+1), $text_color, $font_name, $samtext);
@imagettftext($destImage, $font_height, 0, $font_x, ($font_y-1), $text_color, $font_name, $samtext);
@imagettftext($destImage, $font_height, 0, ($font_x+1), $font_y, $text_color, $font_name, $samtext);
@imagettftext($destImage, $font_height, 0, ($font_x-1), $font_y, $text_color, $font_name, $samtext);
@imagettftext($destImage, $font_height, 0, ($font_x+1), ($font_y-1), $text_color, $font_name, $samtext);
@imagettftext($destImage, $font_height, 0, ($font_x-1), ($font_y-1), $text_color, $font_name, $samtext);
@imagettftext($destImage, $font_height, 0, ($font_x+1), ($font_y+1), $text_color, $font_name, $samtext);
@imagettftext($destImage, $font_height, 0, ($font_x-1), ($font_y+1), $text_color, $font_name, $samtext);
$text_color = @ImageColorAllocate($destImage, 255, 255, 255);
@imagettftext($destImage, $font_height, 0, $font_x, $font_y, $text_color, $font_name, $samtext);
@imagettftext($destImage, $font_height, 0, $font_x, $font_y, $text_color, $font_name, $samtext);
@imagettftext($destImage, $font_height, 0, $font_x, $font_y, $text_color, $font_name, $samtext);
#imagettftext($destImage, $font_height, 0, $font_x, $font_y, $text_color, $font_name, $samtext);
echo $destImage;
switch($type) {
case IMG_GIF:
@imagegif($destImage, "$imgthumb");
break;
case IMG_JPG:
@imagejpeg($destImage, "$imgthumb");
break;
case IMG_PNG:
@imagepng($destImage, "$imgthumb");
break;
case IMG_WBMP:
@imagewbmp($destImage, "$imgthumb");
break;
}
@imagedestroy($srcImage);
@imagedestroy($destImage);
} else {
// return $imgfile;
}
} else {
// return $imgfile;
}
} |