我有这个代码的水印文本到一个图像
if($type==".jpg" or $type==".jpeg"){
$im = imagecreatefromjpeg($uploaddir.$randnum);
}elseif($type==".gif"){
$im = imagecreatefromgif($uploaddir.$randnum);
}else{
$im = imagecreatefrompng($uploaddir.$randnum);
}
$imagesize = getimagesize($uploaddir.$randnum);
$x_offset = 7;
$y_offset = 8;
$textcolor = imagecolorallocate($im, 0xCC, 0xCC, 0xCC);
$textcolor2 = imagecolorallocate($im, 0x00, 0x00, 0x00);
imagestring($im, 5, $x_offset, $y_offset, strtoupper($_POST['code']), $textcolor2);
if($type==".jpg" or $type==".jpeg"){
imagejpeg($im,$uploaddir.$randnum,100);
}elseif($type==".gif"){
imagegif($im,$uploaddir.$randnum,100);
}else{
imagepng($im,$uploaddir.$randnum,8);
}上面的代码是打印左上角的水印...但我希望它写在右下角。
有没有需要帮助的人
问候
发布于 2012-02-24 06:38:33
在您当前正在使用imagestring()的地方尝试使用它。
$font_size = 5;
$margin = 7;
$text_width = imagefontwidth($font_size)*strlen($_POST['code']);
$text_height = imagefontheight($font_size); //assuming it's one line
imagestring($im, $font_size, $imagesize[0] - $text_width - $margin, $imagesize[1] - $text_height - $margin, strtoupper($_POST['code']), $textcolor2);更改$margin和$font_size以满足您的需求。
发布于 2012-02-24 06:28:46
这是实际放置水印的行:
imagestring($im, 5, $x_offset, $y_offset, strtoupper($_POST['code']), $textcolor2);水印的水平位置将取决于您将$x_offset设置为什么。现在它是7,这意味着从左边开始有7个像素。
要将其设置为右侧的7个像素,请将其设置为整个图像的宽度减去(7 +水印的宽度)
用imagettfbbox找出水印的宽度。
设置垂直位置的原则是相同的。
发布于 2012-02-24 06:30:14
如果你想将它移到底部,只需将y偏移量更改为图像的底部,而不是'8‘(可能接近顶部):
$y_offset = $imagesize['height'] - 7;https://stackoverflow.com/questions/9422306
复制相似问题