473,415 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,415 software developers and data experts.

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
Mar 13 '08 #1
2 2527
On Thu, 13 Mar 2008 18:18:13 +0100, la***********@zipmail.com
<la***********@zipmail.comwrote:
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 = "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
Mar 13 '08 #2
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 <an*******@freemail.ru>

Apr 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gerrit Holl | last post by:
Hi, the FAQ says: > For example, a Cartesian coordinate is appropriately represented as a > tuple of two or three numbers. I find it strange to use tuples for a coordinate. After all, a...
5
by: Darren Grant | last post by:
Hi there, I've attempted to implement an Angle class. An Angle is a subset of an integer, where the range is [0,360). All other operations should be permitted. The code works, I think......
1
by: Siegfried Heintze | last post by:
I want to implement drag and drop for tables, divs, spans. The problem is that I don't know how wide or long my tables, divs and spans are going to be in advance so I cannot use absolute...
4
by: CroDude | last post by:
I've made a custom groupbox control. Inside, as one of it's members is CSimpleGradient object. CSimpleGradient is a wrapper class for gradient usage. Basically it looks like that: public class...
9
by: pcnerd | last post by:
I created a demo program with a status bar & status bar label on the form. When the program runs, it's maximized. When I move the mouse over the form, I can see the X & Y coordinates changing on...
8
by: giloosh | last post by:
how would i get the distance and angle between 2 points on the screen. For example: what is the distance between (100,50) and (250,70) what i really wanna do is see how far the current mouse...
3
by: jackiepatti | last post by:
QUESTION: I have a web page containing a form that contains an image instead of a submit button, e.g. <form name='myform' action='get' method='otherpage.asp'> <input type='image'...
12
eragon
by: eragon | last post by:
Im trying to put a captcha image in my site to stop people from spamming, and when i view the image its self i get this: Fatal error: Call to undefined function imagettfbbox() in...
0
by: mingke | last post by:
Hi.... I'm having difficulties with my codes to list coordinates (in my example codes is 4x4 pixel). I tried two different codes and the results are different.Basically, I tried to declare the sub...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.