f



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,$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
0
3/13/2008 5:18:13 PM
comp.lang.php 32646 articles. 0 followers. Post Follow

2 Replies
401 Views

Similar Articles

[PageSpeed] 0

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
0
3/13/2008 5:31:59 PM
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 time
to uncover this info by my own trials and errors.


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

0
anrdaemon (327)
4/2/2008 10:21:52 PM
Reply:

Similar Artilces:

Trace on change/Signal on change/Call on change
Is ooRexx getting any closer to having a mechanism which could be used to trace when a particular variable or stem variable gets changed (to a particular value)? I don't know whether I'm writing cleverer bugs, or my debugging skills are waning with age, but it is starting to take me days to track down some problems that would be a snip with a variable monitor. I've just fixed such a bug. It took me about three years, because it happened only once a year, on average. Phew! -- Steve Swift http://www.swiftys.org.uk/swifty.html http://www.ringers.org.uk Swifty wrote: > Is ...

DST to change or not to change?
Should the clocks be changed twice a year or not? (not that we have much say in the matter) Some think it saves lives by avoiding traffic accidents and note the advantages of a coordinated timekeeping system for trade. http://www.theglobeandmail.com/servlet/story/RTGAM.20050811.wdaylight0810/BNStory/National Since most of Canada is between north latitude 49 deg to 90 deg, and the days and nights are longer the further north you go, the arguments for saving daylight seem to be overwhelmed by the larger natural changes. OTOH DST is not needed at smaller latitudes in the tropics. ...

how to change the change defaults
hi friends, it might be a stupid question to state. but i really need to know while programming, to change the defaults like changing the engineering notation of a real quantity i.e. fraction values or change the fix parameters to denote real value if our calculations involve the values as low as 0.000000001 and as high as 10000000. thanks hemu bisht ...

Changes and frequency of changes
Hi, I observe variable x over time (from 1999-2005) for a large number of firms, w. I have computed the change in variable x from one year to the next. Now, I would like to identify whether variable x has changed from one year to the next for each firm as well as how often it changed for each firm(in some cases I expect no change in this variable i.e. 0). Any suggestions on how to do this in sas? Thanks On Sat, 28 Apr 2007 15:08:15 -0400, mcolowasth@YAHOO.CO.UK wrote: >Hi, > >I observe variable x over time (from 1999-2005) for a large number of >firms, w. I have computed the ...

iTunes changed my changes
Don't know when it happened- could have been with the update of iTunes prior to the update of iOS7, but here's what happened: A few weeks ago, I changed the name of the four movements of a Mozart Symphony so that it would appear separately from the exact same symphony by another artist. This is the default which I had: Mozart: Symphony #41 In C, K 551, "Jupiter" - 1. Allegro Vivace which I changed to: Mozart: S41 In C, K 551, "Jupiter" - 1. Allegro Vivace The separation worked as expected. BUT: Somewhere, somehow the changes got reverted to what ...

coordinates changing
Hi have an image f(x,y) of 200x200 and I must normalize it. The normalize image must be g(x,y) = f(x/a+Xm,y/a+Xm); I am able to calculate "a" and "Xm" but I don't able to rapresent the image in the new coordinates. How can I do to rapresent the new image? Thanks "Marco" <bobbaNOSPAM@mfn.unipmn.it> wrote in message news:ef52ac7.-1@webcrossing.raydaftYaTP... > Hi have an image f(x,y) of 200x200 and I must normalize it. > > The normalize image must be > > g(x,y) = f(x/a+Xm,y/a+Xm); > I am able to calculate "a" and "Xm...

Change Density when Changing Configurations...
Hello, SW does not seem to be able to distinguish the change in density when I change configurations on drawings. What I always get is the mass for the "active" configuration of the part. The same part could have different configurations for different types of material and so the mass should change on a drawing when I change sheets to show different configurations of the same part. This issue seems elementary but I don't know how to accomplish it. Any insight would be greatly appreciated! Example: (not a real life project) I want to produce a bunch of cast iron cubes x 6"...

icon changes with change of extension
when we change the extension of a file in windows, its icon also changes..... how does windows do tht. in my application i require a similar approach. i want the icon to be dependent on the file extension not on the attributes of the file. i have gone trough the registry but things are not very clear. Windows has listed all the file extensions avaliable there, but there is no general way to extract icons for those extension... kindly help Windows displays the icon of the program associated with the file, so if you change a file from ".doc" to ".txt" then the...

Change Status greyed out
I had to reconstruct my Out box because of a software error which had defaulted the message status of all mails to a uniform red (crossed) ball. The '.001' and '.002'-versions of the Out.toc and -.mbx were of no avail. Thanks to other backup files I could restore it all but for the last few days. Now when I right-click the Status column for a particular message belonging to those last days, the 'Change Status'-options are all greyed out. I want for example, change the status to 'Sent'. of the How can I accomplish this? On Thu, 23 Jul 2009 09...

icon changes with change of extension
when we change the extension of a file in windows, its icon also changes..... how does windows do tht. in my application i require a similar approach. i want the icon to be dependent on the file extension not on the attributes of the file. i have gone trough the registry but things are not very clear. Windows has listed all the file extensions avaliable there, but there is no general way to extract icons for those extension... kindly help "Nicky" <nemesia31@gmail.com> wrote in message news:1161232961.150819.220880@i3g2000cwc.googlegroups.com... > when we change the exte...

Category change and the change log
Andy/Blair, There's a small problem in D6 which, when adding a category to a method, results in the category change not being registered in the change log. The problem only occurs when the change is made in one of the possible ways. Demo (in a ClassBrowser)- - Select a method, any method. - Right click, select "Add to category" - Select one of the suggested categories The browser reflects the additional category but if you look at the end of the change log then the category change hasn't been appended to the file If you change the category using drag drop o...

Re: Changes and frequency of changes
On Sat, 28 Apr 2007 15:08:15 -0400, mcolowasth@YAHOO.CO.UK wrote: >Hi, > >I observe variable x over time (from 1999-2005) for a large number of >firms, w. I have computed the change in variable x from one year to the >next. > >Now, I would like to identify whether variable x has changed from one year >to the next for each firm as well as how often it changed for each firm(in >some cases I expect no change in this variable i.e. 0). > >Any suggestions on how to do this in sas? > >Thanks Generate test data, since original poster did not provide it: dat...

changing throw(...) changes interface?
Hi, does adding a throw(...) or throw() to a method or just changing the number of exceptions listed within a throw change the interface? Example: having a class with a method within a class library class x { .... void f() [or void f() throw( int )] }; and changing it to class x { ... void f() throw() [or throw( int ) and so on] [or void f() throw( int, char*) respectively] }; will the library still be binary compatible? Regards, Daniel Daniel Etzold wrote: > does adding a throw(...) or throw() to a method or just changing > the number of exceptions listed within a thro...

Cursor changing and not changing back
I have seen several instances of the cursor changing to something other than what it's supposed to be and getting stuck there. It may be that it changes to something appropriate for the situation and gets stuck, or it may be something random, I don't know. Either way, the only way I have figured out to fix it is to close SW & reopen. Anyone else seeing this, have a better idea what causes it, have a better solution to get it working again? It's not just my machine, and it appears to be quite random - frustrating. WT Wayne Tiffany wrote: > I have seen severa...

How to Manage the Change within the Change?
How can we manage change to software that is not completely tested? For example: For a fictitious name I will use "Big Company Software" (BCS) 1.01.00. Each month BCS goes through the following cycle: Evaluate and Accept Customer Requests Plan Design Develop Build Test User Test Deployment So for example in month 1 BCS 1.01.00 is released. On month 2 BCS 1.02.00 is released etc. Also for example the evaluation, plan, design and development takes place in the first 20 days of the month and test/ user test takes place in the last 10. But on month 2, on day 5 for...

Changing coordinates
Instead of having the x and y coordinates start at the top right corner, I prefer them to start either at the center of the window. This I can do with: .... class CustomPanel extends JPanel { public void paintComponent(Graphics painter) { painter2D = (Graphics2D)painter; painter2D.translate(width/2, height/2); .... But I would also prefer the positive values across the y axis to be positive above the base line and negative below. I could use painter2D.rotate(-Math.PI/2); but then of course the x axis and the y axis ...

how to change the change defaults #2
hi friends, it might be a stupid question to state. but i really need to know while programming, to change the defaults like changing the engineering notation of a real quantity i.e. fraction values or change the fix parameters to denote real value if our calculations involve the values as low as 0.000000001 and as high as 10000000. thanks hemu bisht ...

Picture changes when record changes
Hi fellas, Im setting up a form in my Access project and I need to implement this rather special fucntion. This function is basically simple to understand but I really dont know how to create it. I need to implement a function that each time their is a record navigation a picture changes. Meaning = lets say I have a field with the word "football" in it - and their is a picture of a football next to it. Then I change record = changed into "rugby" and then their is a picture of a rugby ball next to it. How can I do that function? Cheers.. nickybon On 2 May 2006 09:24:3...

Changing the Change File Feature.
Is there a way to turn off the feature in Windows XP Home where, when a shortcut can't find its target file, it gets changed to point to a similarly-named file in another directory? Thanks. It does not get changed automatically. Just Click NO! -- Hope this helps. Let us know. Wes MS-MVP Windows Shell/User In news:bPVue.8700$NX4.8680@newsread1.news.pas.earthlink.net, Neil <nospam@nospam.net> hunted and pecked: > Is there a way to turn off the feature in Windows XP Home where, when a > shortcut can't find its target file, it gets changed to point to a > simila...

How to change a function in cartesian coordinates in polar coordinates?
Hello, I'm a MATLAB beginner. This is my problem. I have a function in cartesian coordinates f(x,y) and j points (xj, yj) (ex. f(x,y)=x.^2+y). 1. Firstly, I want to trasform this function in polar coordinates. I used "cart2pol" to trasform the points and I obtained j points (rhoj, thetaj), but how can I trasform every function f(x,y) into F(rho, theta)? I would like to have the analytic form of F. 2. Secondly, I suppose to have F(rho, theta). Now I want to fix the radius and to consider theta the only variable. How can I do? Many thanks to your help! "Valentina...

The data has been changed. Another user edited this record and saved the changes before you attempted to save your changes. Re-edit the record
Hi All, I have a form and VB code in Access. The code is like With rs .Edit !Field = 10 .Update End With When I chang a value on the form. then the error shows up. The data has been changed. Another user edited this record and saved the changes before you attempted to save your changes. Re-edit the record Anyone has idea what cause that? Thanks in advance. In most cases, I have seen, this happens, if you have two subforms or forms linked to the same table. If you try to edit the table from a different form while the second form/subfrm (linked to the same ...

FAQ: I {changed directory, modified my environment} in a perl script. How come the change disappeared when I exited the script? How do I get my changes to be visible?
This message is one of several periodic postings to comp.lang.perl.misc intended to make it easier for perl programmers to find answers to common questions. The core of this message represents an excerpt from the documentation provided with Perl. -------------------------------------------------------------------- 8.34: I {changed directory, modified my environment} in a perl script. How come the change disappeared when I exited the script? How do I get my changes to be visible? Unix In the strictest sense, it can't be done--the script executes as a different proc...

Speed Change without Pitch Change
Does anyone know of a C/C++ library for taking an audio file and performing a speed change without changing the pitch? Thanks, Jeff Dodson > Does anyone know of a C/C++ library for taking an audio file and > performing a speed change without changing the pitch? > Jeff, The simple way to do it is just to repeat or cut out the small chunks of data depending if you are going faster or slower respectively. Divide your file into the frames of ~10ms long and operate frame by frame. A better way for doing the speed change is the same method however the signal is split into frq. su...

OT: change of server, change of luck
Is this post getting through to you guys? My NSP has just dropped their Usenet support altogether (argh), and I'm experimenting with public servers (news.aioe.org for now). -- // }{idehiko ()gata "I hope I didn't hurt you too much \X/ Amiga since '86 when I killed you..." - Elmer Fudd bekkoame is a classic Japanese candybar. "Hidehiko Ogata" <hog@aqu.candybar.ne.jp> wrote in message news:S3.F3.bb2XEZ0a85dg3Kf.NR@aqu.candybar.ne.jp... > Is this post getting through to you guys? My NSP has just dropped > their Usenet support ...

Web resources about - Why do imagettfbbox coordinates change when angle changes? - comp.lang.php

Issues · facebook/hhvm · GitHub
hhvm - A virtual machine designed for executing programs written in Hack and PHP.

Resources last updated: 3/7/2016 8:10:47 AM