Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

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,$t
ext);
$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,$font,$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

Report this thread to moderator Post Follow-up to this message
Old Post
laredotornado@zipmail.com
03-14-08 12:10 AM


Re: Why do imagettfbbox coordinates change when angle changes?
On Thu, 13 Mar 2008 18:18:13 +0100, laredotornado@zipmail.com  =

<laredotornado@zipmail.com> wrote:
> 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

> But I
> am getting two distinct sets of coordinates if I change the angle from=

> zero to 270.
>
> Here's the relevant code:
>
>         $text =3D "hello";
>         $s =3D getImageSize($img_file);
>         $imgWidth =3D $s[0];
>         $imgHeight =3D $s[1];
>          $source=3DImageCreateFromJPEG($img_file)
;
>         $size=3D16;
>          $black=3Dimagecolorallocate($source,0,0,
0);
>         $font=3D'/usr/share/fonts/msttcorefonts/times.ttf';
>          $bbox=3Dimagettfbbox($size,$angle,$font,
$text);
>         $textWidth=3D$bbox[2]-$bbox[0];
>         $textHeight=3D$bbox[5]-$bbox[3];
>         $x=3D($imgWidth/2)-($textWidth/2);
>         $y=3D($imgHeight/2)-($textHeight/2);
>          imagettftext($source,$size,$angle,$x,$y,
$black,$font,$text );
>         header("Content-type: image/jpeg");
>
> When I print out the bbox with 0, I get
>
> Array ( [0] =3D> -3 [1] =3D> -1 [2] =3D> 41 [3] =3D> -1 [4] =3D> 41 [5=
] =3D> -16
> [6] =3D> -3 [7] =3D> -16 )
>
> with 270, I get
>
> Array ( [0] =3D> -13 [1] =3D> -1 [2] =3D> -13 [3] =3D> 41 [4] =3D> -1 =
[5] =3D> 41
> [6] =3D> -1 [7] =3D> -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 wi=
th  =

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 te=
xt  =

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

Report this thread to moderator Post Follow-up to this message
Old Post
Rik Wasmus
03-14-08 12:10 AM


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,

> (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 ti
me
to uncover this info by my own trials and errors.


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


Report this thread to moderator Post Follow-up to this message
Old Post
AnrDaemon
04-03-08 12:20 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:16 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.