如何计算在我的班级中写入水印文本的位置

发布于 2024-12-08 02:54:53 字数 1897 浏览 0 评论 0原文

我刚刚完成在图像上制作水印文本的课程,

这是我的问题

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城°AllureLove 2024-12-15 02:54:53

离开显示器,拿起一支铅笔和一张纸,画一些图:

    watermark in the bottom-right corner

            img_width
            |----------- -----------------|<--|
            |                             |   |
            |                             |   |
            |                             |   |
            |                             |   |
            |                             |   | mark Y offset 
img_height  |                             |   |
            |                             |   |
            |                             |   |
            |                             |   |
            |                mark_width   |   |
            |               |-------------|<--|
            |               |             |
            |   mark_height |             |
            |               |             |
            |-----------------------------|
            ^               ^
            |_______________|
            mark X offset

如何计算 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:

    watermark in the bottom-right corner

            img_width
            |----------- -----------------|<--|
            |                             |   |
            |                             |   |
            |                             |   |
            |                             |   |
            |                             |   | mark Y offset 
img_height  |                             |   |
            |                             |   |
            |                             |   |
            |                             |   |
            |                mark_width   |   |
            |               |-------------|<--|
            |               |             |
            |   mark_height |             |
            |               |             |
            |-----------------------------|
            ^               ^
            |_______________|
            mark X offset

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文