如何计算在我的班级中写入水印文本的位置
我刚刚完成在图像上制作水印文本的课程,
这是我的问题
1 - 用户选择字体文件
2 - 用户选择字体颜色
3 - 用户选择水印位置
4 - 用户选择字体大小
所以 - 我的问题是如何计算正确的位置取决于字体大小,
这里是我的代码,我刚刚尝试过
`
$width = 400; //图像宽度
$height = 300; //图像高度
if($this -> text_posi == 'topleft'){
$x1 = ($width - $width ) + 20;
$y1 = ($height - $height) + 40;
}elseif($this -> text_posi == 'topright'){
$x1 = $width - 200;
$y1 = ($height - $height) + 40;
}
elseif($this -> text_posi == 'bottomleft'){
$x1 = ($width - $width ) + 20;
$y1 = $height - 30;
}
elseif($this -> text_posi == 'bottomright'){
$x1 = $width - 200;
$y1 = $height - 30;
}
elseif($this -> text_posi == 'topcenter'){
$x1 = $width * .5 - 100;
$y1 = ($height - $height) + 30;
}
elseif($this -> text_posi == 'bottomcenter'){
$x1 = $width * .5 - 100;
$y1 = $height - 30;
}
elseif($this -> text_posi == 'rightcenter'){
$x1 = $width - 180;
$y1 = $height * .5;
}
elseif($this -> text_posi == 'leftcenter'){
$x1 = $width - $width + 20;
$y1 = $height * .5 ;
}else{
$x1 = ($width / 2) - 30;
$y1 = ($height / 2) - 20 ;
}
`
我认为如果图像宽度大于等于 500 且高度大于等于 500
就可以了,请帮忙
i just finished my class to make water mark text on image
here is my problem
1 - user select font file
2 - user select font color
3 - user select watermark position
4 - user select font size
So - my problem is how to calculate the right position depended on font size , family
here is my code i just tried
`
$width = 400; //image width
$height = 300; //image height
if($this -> text_posi == 'topleft'){
$x1 = ($width - $width ) + 20;
$y1 = ($height - $height) + 40;
}elseif($this -> text_posi == 'topright'){
$x1 = $width - 200;
$y1 = ($height - $height) + 40;
}
elseif($this -> text_posi == 'bottomleft'){
$x1 = ($width - $width ) + 20;
$y1 = $height - 30;
}
elseif($this -> text_posi == 'bottomright'){
$x1 = $width - 200;
$y1 = $height - 30;
}
elseif($this -> text_posi == 'topcenter'){
$x1 = $width * .5 - 100;
$y1 = ($height - $height) + 30;
}
elseif($this -> text_posi == 'bottomcenter'){
$x1 = $width * .5 - 100;
$y1 = $height - 30;
}
elseif($this -> text_posi == 'rightcenter'){
$x1 = $width - 180;
$y1 = $height * .5;
}
elseif($this -> text_posi == 'leftcenter'){
$x1 = $width - $width + 20;
$y1 = $height * .5 ;
}else{
$x1 = ($width / 2) - 30;
$y1 = ($height / 2) - 20 ;
}
`
I ThInk It fine if image more than width >= 500 and height >= 500
Can You Help Please
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
离开显示器,拿起一支铅笔和一张纸,画一些图:
如何计算 X 和 Y 偏移值应该立即显而易见。要了解水印有多大,请使用 http://www.php.net /manual/en/function.imagettfbbox.php
Turn away from your monitor, grab a pencil and a piece of paper and draw some pictures:
It should be immediately obvious how to calculate the values for X and Y offsets. To find out how big the watermark is, use http://www.php.net/manual/en/function.imagettfbbox.php