Re: [PHP] TrueType font changes size when rotated?

2007-04-27 Thread Richard Lynch
On Thu, April 26, 2007 7:14 am, Tijnema ! wrote:
 On 4/26/07, Richard Lynch [EMAIL PROTECTED] wrote:
 On Wed, April 25, 2007 3:33 pm, Seth Price wrote:
  I downloaded your image, enlarged it, and measured it out in
  photoshop. The distance from the center to the left side is 131px,
  and center to right side is 129px. Diameter to top is 129px, and
 to
  bottom is 130px.
 
  While it may not be an obvious ellipse, it's enough to throw off
 my
  calculations.

 Enlarged it how?

 I guess he meant to zoom, so that he could actually count the pixels
 :)

Same smell.

Once you do zoom counting pixels will never be exact.

The zoom function had to deal with rounding errors and chose to
either add a pixel or not.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated?

2007-04-27 Thread Tijnema !

On 4/27/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Thu, April 26, 2007 7:14 am, Tijnema ! wrote:
 On 4/26/07, Richard Lynch [EMAIL PROTECTED] wrote:
 On Wed, April 25, 2007 3:33 pm, Seth Price wrote:
  I downloaded your image, enlarged it, and measured it out in
  photoshop. The distance from the center to the left side is 131px,
  and center to right side is 129px. Diameter to top is 129px, and
 to
  bottom is 130px.
 
  While it may not be an obvious ellipse, it's enough to throw off
 my
  calculations.

 Enlarged it how?

 I guess he meant to zoom, so that he could actually count the pixels
 :)

Same smell.

Once you do zoom counting pixels will never be exact.

The zoom function had to deal with rounding errors and chose to
either add a pixel or not.


Did you ever used zoom in Adobe Photoshop CS3? You can zoom until the
pixels are about 1CM on the screen. If you still are going to tell me
that it would differ if there was to add a pixel or not. Didn't
checked with photoshop either, but i there's a good chance that the OP
is true. As he is using photoshop.


Tijnema

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated?

2007-04-26 Thread Tijnema !

On 4/26/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Wed, April 25, 2007 3:33 pm, Seth Price wrote:
 I downloaded your image, enlarged it, and measured it out in
 photoshop. The distance from the center to the left side is 131px,
 and center to right side is 129px. Diameter to top is 129px, and to
 bottom is 130px.

 While it may not be an obvious ellipse, it's enough to throw off my
 calculations.

Enlarged it how?


I guess he meant to zoom, so that he could actually count the pixels :)



As soon as you scale an image, rounding errors are introduced...

Take his source, maybe with a font 10 X bigger,  and then using
imagecolorat to examine each pixel in the original, and see if it's
off...

And, really, if drawing text with a 1-pixel error margin throws you
off, you're in trouble anyway...


It just shouldn't be like that :)


Though the super dark 90-degree text versus the others with much
larger variations in length is disconcerting, in your image, if those
length calculations are correct...



Still, it has probably nothing to do with PHP, as PHP is just using
the GD library

Tijnema

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated?

2007-04-26 Thread tedd

At 2:14 PM +0200 4/26/07, Tijnema ! wrote:

On 4/26/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Wed, April 25, 2007 3:33 pm, Seth Price wrote:

 I downloaded your image, enlarged it, and measured it out in
 photoshop. The distance from the center to the left side is 131px,
 and center to right side is 129px. Diameter to top is 129px, and to
 bottom is 130px.

 While it may not be an obvious ellipse, it's enough to throw off my

  calculations.

And, really, if drawing text with a 1-pixel error margin throws you
off, you're in trouble anyway...


It just shouldn't be like that :)


Yeah, in a prefect world it would be. But I think Seth, as well as 
the people he reported the bug to, are going to find that while we 
can compute exactly what any measurement should be, we also have to 
pass it through the user's browser and user's monitor to display it.


I don't even want to get into how the various browsers display data, 
let alone how different monitors might. The combinations here are 
staggering. Granted, the OP is using a Mac and that comes as close as 
most can be, but even Apple's standards have been influenced by M$ 
(another OT subject).


However, I'm actually surprised that the error was as small as it was 
-- we're talking about less than 0.5 percent by using his 
measurements.


Also, please note that if you move the center of the image a single 
pixel to the lower-left, then the error is only a single pixel in one 
direction. Who's to say that the OP did not realize nor use where 
zero-zero actually was?


I seem to recall that when one has to make a decision as to where a 
pixel is placed, we use the lower left corner as the coordinates and 
not the center of the pixel -- similar as we do for displaying 
characters -- is that not correct?


In any event, if it were me, I would use the center of the locus of 
points to calculate error.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated?

2007-04-25 Thread tedd

At 10:26 PM -0500 4/24/07, Seth Price wrote:

Hi all! I've been programming GD and PHP for a while, but I haven't
done much with font drawing. I'm trying to layout and draw text, but
the text actually changes size and shape depending on the angle it's
drawn at. This is making it extremely difficult to lay the text out
properly.

Am I doing something wrong? Is there a bug in FreeType? How can I
consistently draw text?

For example:
The following code draws 'Hello world' at differing angles. But all
drawings are at right angles to each other. FreeType shouldn't even
need to do any resampling or interpolating, but each text is drawn
with a unique length and look. You can see the output of the
following code here:
http://leopold.sage.wisc.edu/test2.php


Seth:

Everything looks fine to me. On my browser all the text is the same 
size (I measured it). But then again, I'm using Safari for the Mac. 
Maybe it's a browsers problem.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated?

2007-04-25 Thread Seth Price
I'm using Safari for Mac also. What are the numbers after 'Hello  
world' coming out for you?

~Seth


On Apr 25, 2007, at 11:05 AM, tedd wrote:


At 10:26 PM -0500 4/24/07, Seth Price wrote:

Hi all! I've been programming GD and PHP for a while, but I haven't
done much with font drawing. I'm trying to layout and draw text, but
the text actually changes size and shape depending on the angle it's
drawn at. This is making it extremely difficult to lay the text out
properly.

Am I doing something wrong? Is there a bug in FreeType? How can I
consistently draw text?

For example:
The following code draws 'Hello world' at differing angles. But all
drawings are at right angles to each other. FreeType shouldn't even
need to do any resampling or interpolating, but each text is drawn
with a unique length and look. You can see the output of the
following code here:
http://leopold.sage.wisc.edu/test2.php


Seth:

Everything looks fine to me. On my browser all the text is the same  
size (I measured it). But then again, I'm using Safari for the Mac.  
Maybe it's a browsers problem.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated? (the plot thickens)

2007-04-25 Thread Seth Price

So I've rewritten my script in C. You can find the source here:
http://leopold.sage.wisc.edu/testing/gd_ft_ang.c

This script links directly to GD and produces a still different  
output. On my home system, the output image is correct and the length  
89 px. On the web server, the output image is not correct, but a bit  
more consistent than the output from PHP. You can see it here:

http://leopold.sage.wisc.edu/testing/gd35_ft15.3.png

What is the difference between my home system and the web server? The  
web server is running the most current versions, but my home system  
is not. So, that's odd. Could some of you with GD and FreeType  
installed take a look at my source code and see if my output image  
matches yours?


To help eliminate variables, you can download a copy of the font file  
I'm using here:

http://leopold.sage.wisc.edu/testing/Verdana.ttf

It sounds like this may be a bug in GD or FreeType.
Thanks,
Seth



On Apr 25, 2007, at 12:29 AM, jekillen wrote:



On Apr 24, 2007, at 8:26 PM, Seth Price wrote:


Hi all! I've been programming GD and PHP for a while, but I haven't
done much with font drawing. I'm trying to layout and draw text, but
the text actually changes size and shape depending on the angle it's
drawn at. This is making it extremely difficult to lay the text out
properly.

Am I doing something wrong? Is there a bug in FreeType? How can I
consistently draw text?

For example:
The following code draws 'Hello world' at differing angles. But all
drawings are at right angles to each other. FreeType shouldn't even
need to do any resampling or interpolating, but each text is drawn
with a unique length and look. You can see the output of the
following code here:
http://leopold.sage.wisc.edu/test2.php


?php
header('Content-Type:image/png');

$img = imagecreatetruecolor(300, 300);
$bak = imagecolorexact($img, 255,255,255);
imagefill($img, 0,0, $bak);
$col = imagecolorexact($img, 0,0,0);

for($i = 0; $i  360; $i += 90){
$b = imageftbbox(12, $i, '/Library/WebServer/Verdana.ttf', 'Hello
world');
$len = sqrt(($b[2] - $b[0])*($b[2] - $b[0]) + ($b[3] - $b[1])*(($b
[3] - $b[1])));
imagefttext($img, 12, $i, 150, 150, $col, '/Library/WebServer/
you're using Mac OSX, did you have to install gd or does it now  
come with
gd included in the php installation? (after looking further down  
the message,

I see you are running Server, so that is probably the difference)
Mine did not (OSX 1.4x). I have it installed on a FreeBSD system.
www.brushandbard.com - web design - dynamic image generation  
demonstration

and Word Wise the Tile Puzzle are some of my projects using gd.

Verdana.ttf', 'Hello world '.$len);
}

imagepng($img);
?

When using more interesting fonts, this 'resampling' is causing text
drawn at 90 deg to look fugly. What can I do to prevent this? Is this
a known issue? The output doesn't seem to change if I use the 'ttf'
functions vs. the 'ft' functions.
I went looking for some samples, as I have played with this some in  
the
past, but did not find anything current to show. I do not remember  
having
this problem. There may be a distortion that is being entered into  
the mix

when the fonts are rendered by your code. $len is the hypoteneus of a
right triangle, right off hand I would say that is your problem or  
some of it.
The length should be a linear measurement and not a diagonal  
measurement.
But I am rusty at this point. Also there is a function for  
explicitly specifying

the angle of the font in degrees, and, as I remember the angle of the
rendering box also. This is so each font can be rendered at an  
individual

angle and the whole enclosing box, so the whole word is rotated.
 you will have to look in the manual for gd related functions if  
you are

not aware of this.
Jeff K


System info:
Mac v10.4 Server running PHP v5.2.1  FreeType v2.3.4

Compiled with:
'./configure' '--with-apxs' '--with-mysqli=/usr/local/mysql/bin/
mysql_config' '--with-gd' '--with-png-dir=/usr/local' '--with-zlib-
dir=/usr' '--with-jpeg-dir=/usr/local' '--disable-short-tags' '-- 
with-

iconv' '--enable-exif' '--enable-mbstring' '--enable-gd-native-ttf'
'--with-freetype-dir=/usr/local'

Thanks,
Seth

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated?

2007-04-25 Thread tedd
Yep, I'm calculating the length from the returned bounding box and 
printing it out. The box seems to randomly expand and shrink 
depending on the angle.

~Seth


~Seth:

I think it's your calculation of the bounding box that's throwing you 
off -- maybe round off errors -- I don't know. However, I don't see 
any difference in the length of the text.


The following shows Hello World . at one degree increments over 360 degrees.

http://sperling.com/a/font/

It looks like a circle to me. If there was a difference, then it 
would be elliptical.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated?

2007-04-25 Thread Seth Price
I downloaded your image, enlarged it, and measured it out in  
photoshop. The distance from the center to the left side is 131px,  
and center to right side is 129px. Diameter to top is 129px, and to  
bottom is 130px.


While it may not be an obvious ellipse, it's enough to throw off my  
calculations.

~Seth


On Apr 25, 2007, at 1:38 PM, tedd wrote:

Yep, I'm calculating the length from the returned bounding box and  
printing it out. The box seems to randomly expand and shrink  
depending on the angle.

~Seth


~Seth:

I think it's your calculation of the bounding box that's throwing  
you off -- maybe round off errors -- I don't know. However, I don't  
see any difference in the length of the text.


The following shows Hello World . at one degree increments over  
360 degrees.


http://sperling.com/a/font/

It looks like a circle to me. If there was a difference, then it  
would be elliptical.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated?

2007-04-25 Thread Seth Price

I've created a bug report and moved discussion to the GD bug tracker:
http://bugs.libgd.org/?do=detailstask_id=76




On Apr 25, 2007, at 1:38 PM, tedd wrote:

Yep, I'm calculating the length from the returned bounding box and  
printing it out. The box seems to randomly expand and shrink  
depending on the angle.

~Seth


~Seth:

I think it's your calculation of the bounding box that's throwing  
you off -- maybe round off errors -- I don't know. However, I don't  
see any difference in the length of the text.


The following shows Hello World . at one degree increments over  
360 degrees.


http://sperling.com/a/font/

It looks like a circle to me. If there was a difference, then it  
would be elliptical.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated?

2007-04-25 Thread Richard Lynch
On Wed, April 25, 2007 1:38 pm, tedd wrote:
Yep, I'm calculating the length from the returned bounding box and
printing it out. The box seems to randomly expand and shrink
depending on the angle.
~Seth

 ~Seth:

 I think it's your calculation of the bounding box that's throwing you
 off -- maybe round off errors -- I don't know. However, I don't see
 any difference in the length of the text.

 The following shows Hello World . at one degree increments over 360
 degrees.

 http://sperling.com/a/font/

 It looks like a circle to me. If there was a difference, then it
 would be elliptical.

SPHPyrograph!

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated?

2007-04-25 Thread Richard Lynch
On Wed, April 25, 2007 3:33 pm, Seth Price wrote:
 I downloaded your image, enlarged it, and measured it out in
 photoshop. The distance from the center to the left side is 131px,
 and center to right side is 129px. Diameter to top is 129px, and to
 bottom is 130px.

 While it may not be an obvious ellipse, it's enough to throw off my
 calculations.

Enlarged it how?

As soon as you scale an image, rounding errors are introduced...

Take his source, maybe with a font 10 X bigger,  and then using
imagecolorat to examine each pixel in the original, and see if it's
off...

And, really, if drawing text with a 1-pixel error margin throws you
off, you're in trouble anyway...

Though the super dark 90-degree text versus the others with much
larger variations in length is disconcerting, in your image, if those
length calculations are correct...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated?

2007-04-25 Thread Seth Price
I've written the problem in C and linked it directly to GD, and the  
problem still occurs. Though the text is still the *most* random when  
using the PHP version of the library. For more info, see here:

http://bugs.libgd.org/?do=detailstask_id=76

I'm not scaling the image, though, I'm rotating the font. And I'm  
doing it in such a way that the pixels don't need to be resampled to  
transform from one to the next.


Something else, in the C version the problem goes away when the font  
size is 16.


The example font that I'm using here is thrown off by 1-5 pixels, but  
the other font was thrown off more (5-15px).


I think the problem is already partly fixed in the current version of  
GD (v2.0.35RC2). Only the first of the four samples is different. Now  
I just need to get PHP to compile with an external version of GD.

~Seth



On Apr 25, 2007, at 6:30 PM, Richard Lynch wrote:


On Wed, April 25, 2007 3:33 pm, Seth Price wrote:

I downloaded your image, enlarged it, and measured it out in
photoshop. The distance from the center to the left side is 131px,
and center to right side is 129px. Diameter to top is 129px, and to
bottom is 130px.

While it may not be an obvious ellipse, it's enough to throw off my
calculations.


Enlarged it how?

As soon as you scale an image, rounding errors are introduced...

Take his source, maybe with a font 10 X bigger,  and then using
imagecolorat to examine each pixel in the original, and see if it's
off...

And, really, if drawing text with a 1-pixel error margin throws you
off, you're in trouble anyway...

Though the super dark 90-degree text versus the others with much
larger variations in length is disconcerting, in your image, if those
length calculations are correct...

--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] TrueType font changes size when rotated?

2007-04-24 Thread jekillen


On Apr 24, 2007, at 8:26 PM, Seth Price wrote:


Hi all! I've been programming GD and PHP for a while, but I haven't
done much with font drawing. I'm trying to layout and draw text, but
the text actually changes size and shape depending on the angle it's
drawn at. This is making it extremely difficult to lay the text out
properly.

Am I doing something wrong? Is there a bug in FreeType? How can I
consistently draw text?

For example:
The following code draws 'Hello world' at differing angles. But all
drawings are at right angles to each other. FreeType shouldn't even
need to do any resampling or interpolating, but each text is drawn
with a unique length and look. You can see the output of the
following code here:
http://leopold.sage.wisc.edu/test2.php


?php
header('Content-Type:image/png');

$img = imagecreatetruecolor(300, 300);
$bak = imagecolorexact($img, 255,255,255);
imagefill($img, 0,0, $bak);
$col = imagecolorexact($img, 0,0,0);

for($i = 0; $i  360; $i += 90){
$b = imageftbbox(12, $i, '/Library/WebServer/Verdana.ttf', 'Hello
world');
$len = sqrt(($b[2] - $b[0])*($b[2] - $b[0]) + ($b[3] - $b[1])*(($b
[3] - $b[1])));
imagefttext($img, 12, $i, 150, 150, $col, '/Library/WebServer/
you're using Mac OSX, did you have to install gd or does it now come 
with
gd included in the php installation? (after looking further down the 
message,

I see you are running Server, so that is probably the difference)
Mine did not (OSX 1.4x). I have it installed on a FreeBSD system.
www.brushandbard.com - web design - dynamic image generation 
demonstration

and Word Wise the Tile Puzzle are some of my projects using gd.

Verdana.ttf', 'Hello world '.$len);
}

imagepng($img);
?

When using more interesting fonts, this 'resampling' is causing text
drawn at 90 deg to look fugly. What can I do to prevent this? Is this
a known issue? The output doesn't seem to change if I use the 'ttf'
functions vs. the 'ft' functions.

I went looking for some samples, as I have played with this some in the
past, but did not find anything current to show. I do not remember 
having
this problem. There may be a distortion that is being entered into the 
mix

when the fonts are rendered by your code. $len is the hypoteneus of a
right triangle, right off hand I would say that is your problem or some 
of it.
The length should be a linear measurement and not a diagonal 
measurement.
But I am rusty at this point. Also there is a function for explicitly 
specifying

the angle of the font in degrees, and, as I remember the angle of the
rendering box also. This is so each font can be rendered at an 
individual

angle and the whole enclosing box, so the whole word is rotated.
 you will have to look in the manual for gd related functions if you are
not aware of this.
Jeff K


System info:
Mac v10.4 Server running PHP v5.2.1  FreeType v2.3.4

Compiled with:
'./configure' '--with-apxs' '--with-mysqli=/usr/local/mysql/bin/
mysql_config' '--with-gd' '--with-png-dir=/usr/local' '--with-zlib-
dir=/usr' '--with-jpeg-dir=/usr/local' '--disable-short-tags' '--with-
iconv' '--enable-exif' '--enable-mbstring' '--enable-gd-native-ttf'
'--with-freetype-dir=/usr/local'

Thanks,
Seth

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php