开发者

how to calculate where to write watermark text in my class

i just finished my class to make water mark text on image

here is my problem

1 - user select font fil开发者_StackOverflowe

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜