Connecting Tech Pros Worldwide Help | Site Map

Why do imagettfbbox coordinates change when angle changes?

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 13th, 2008, 05:25 PM
laredotornado@zipmail.com
Guest
 
Posts: n/a
Default Why do imagettfbbox coordinates change when angle changes?

Hi,

I'm using php 4.4.4. Maybe I'm misreading the docs, but in the
imagettfbbox manual (http://us2.php.net/imagettfbbox), it says that
text coordinates are the same regardless of what the angle is. But I
am getting two distinct sets of coordinates if I change the angle from
zero to 270.

Here's the relevant code:

$text = "hello";
$s = getImageSize($img_file);
$imgWidth = $s[0];
$imgHeight = $s[1];
$source=ImageCreateFromJPEG($img_file);
$size=16;
$black=imagecolorallocate($source,0,0,0);
$font='/usr/share/fonts/msttcorefonts/times.ttf';
$bbox=imagettfbbox($size,$angle,$font,$text);
$textWidth=$bbox[2]-$bbox[0];
$textHeight=$bbox[5]-$bbox[3];
$x=($imgWidth/2)-($textWidth/2);
$y=($imgHeight/2)-($textHeight/2);
imagettftext($source,$size,$angle,$x,$y,$black,$fo nt,$text );
header("Content-type: image/jpeg");

When I print out the bbox with 0, I get

Array ( [0] =-3 [1] =-1 [2] =41 [3] =-1 [4] =41 [5] =-16
[6] =-3 [7] =-16 )

with 270, I get

Array ( [0] =-13 [1] =-1 [2] =-13 [3] =41 [4] =-1 [5] =41
[6] =-1 [7] =-1 )

I must be misinterpreting the docs. Why are the coordinates
different? - Dave

  #2  
Old March 13th, 2008, 05:35 PM
Rik Wasmus
Guest
 
Posts: n/a
Default Re: Why do imagettfbbox coordinates change when angle changes?

On Thu, 13 Mar 2008 18:18:13 +0100, laredotornado@zipmail.com
<laredotornado@zipmail.comwrote:
Quote:
I'm using php 4.4.4. Maybe I'm misreading the docs, but in the
imagettfbbox manual (http://us2.php.net/imagettfbbox), it says that
text coordinates are the same regardless of what the angle is.
Nope
Quote:
But I
am getting two distinct sets of coordinates if I change the angle from
zero to 270.
>
Here's the relevant code:
>
$text = "hello";
$s = getImageSize($img_file);
$imgWidth = $s[0];
$imgHeight = $s[1];
$source=ImageCreateFromJPEG($img_file);
$size=16;
$black=imagecolorallocate($source,0,0,0);
$font='/usr/share/fonts/msttcorefonts/times.ttf';
$bbox=imagettfbbox($size,$angle,$font,$text);
$textWidth=$bbox[2]-$bbox[0];
$textHeight=$bbox[5]-$bbox[3];
$x=($imgWidth/2)-($textWidth/2);
$y=($imgHeight/2)-($textHeight/2);
imagettftext($source,$size,$angle,$x,$y,$black,$fo nt,$text );
header("Content-type: image/jpeg");
>
When I print out the bbox with 0, I get
>
Array ( [0] =-3 [1] =-1 [2] =41 [3] =-1 [4] =41 [5] =-16
[6] =-3 [7] =-16 )
>
with 270, I get
>
Array ( [0] =-13 [1] =-1 [2] =-13 [3] =41 [4] =-1 [5] =41
[6] =-1 [7] =-1 )
>
I must be misinterpreting the docs. Why are the coordinates
different? - Dave
"The points are relative to the text regardless of the angle , so "upper
left" means in the top left-hand corner seeing the text horizontally."

Which means that with normal text without an angle, you have this box with
the array-indexes:
6,7---------4,5
| |
0,1---------2,3

However, if you have an angle of 180 (text upside down), you see this
picture:
2,3---------0,1
| |
4,5---------6,7

So, 0 & 1 hold the 'lower left corner IF you see the text horizontally' as
opposed to the 'lower left corner if you look at the picture'. The
coordinates WILL change if the angele changes (how could they not?), but
the different indexes will be for the same relative position from the text
if you were to look at the image the way the text appears horizontal
again. (Damned, this is far more easily explained face-to-face by just
rotating a piece of paper...).
--
Rik Wasmus
  #3  
Old April 2nd, 2008, 10:25 PM
AnrDaemon
Guest
 
Posts: n/a
Default Re: Why do imagettfbbox coordinates change when angle changes?

Greetings, Rik Wasmus.
In reply to Your message dated Thursday, March 13, 2008, 21:31:59,
Quote:
(Damned, this is far more easily explained face-to-face by just
rotating a piece of paper...).
QFT :D

Thanks BTW, I was about to use this function myself and You just saved me time
to uncover this info by my own trials and errors.


--
Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.