Little PHPlot problem

cerbere

New Member
Messages
51
Reaction score
1
Points
0
Hi everyone,

Please take a look at this :
http://ixedix.x10hosting.com/MathRec/ (fourth problem)

and at :
http://ixedix.x10hosting.com/MathRec/plotit.php
(invoked by clicking "See a plot here" on the above page).

Why is the y_title rendered incorrectly ?
In "time (seconds)", the i and d letters and the parentheses
are shifted downwards (actually rightwards because of the
90 degrees counter-clockwise text rotation), apparently to clear
some invisible text-box boundary.

Now this used to render fine some months ago. I tried different
font sizes, no success.

I use PHPlot 5.0.5 and X10's GD library. Was that library updated recently ?
The plotting code is here :
http://ixedix.x10hosting.com/mrfishplot.txt

Any help will be greatly appreciated !
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
It is most likely an issue with freetype, PHPlot or GD. When run under Apache 2.2.14+PHP 5.3.1+FreeType 2.3.11+PHPlot 5.1.2, your script displayed the text with no issues. For now, try PHPlot 5.1.2.

I can't currently access my X10 account, so I can't test anything X10, nor determine what versions are installed. Once that's settled, and if I can find the time, I'll look deeper into this (though I make no promises as to success).
 
Last edited:

cerbere

New Member
Messages
51
Reaction score
1
Points
0
Thanks misson, I will try PHPlot 5.1.2, and report the result over here.

As for Eric Raymond and Rick Moen with their arrogant rambling
about an imaginary hacking elite (We the Hackers, you the imbeciles),
I think they are a disgrace to the amateur (hobby) and professional
programming communities. Except for a few common-sense remarks about
how to request help on programming problems, I really don't understand
why they are so often cited here.

Look at "hack", "hacking", "hacker" in a dictionary.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Just tested PHPlot 5.0.5 on my test box and it worked, and tested 5.1.2 on X10 and it didn't, so no help there. X10 (rather, Stoli and Chopin) use PHP 5.2.13+Freetype 2.2.1. All servers tested list the GD extension as using GD version 2.0.34 "compatible" (whatever "compatible" means). The next thing to test is the code that rotates the text (PHPlot::processTextTTF).

Except for a few common-sense remarks about how to request help on programming problems, I really don't understand why they are so often cited here.
If you know of a guide with a better tone, point it out and we'll use it. The tone aside, it covers many the missteps I've seen committed on these very forums.

In their defense, ESR and Rick wouldn't say they're writing about a hacking elite and for everyone else, they're writing about hacker discourse for those in a pre-larval stage. Also, their attitude is partly cultural (though not universal among hackers), which warrants granting a little leeway.

Of course, I understand how the tone irks some people, despite their lampshading of it.

Look at "hack", "hacking", "hacker" in a dictionary.
Such as the jargon file? :)
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Look at "hack", "hacking", "hacker" in a dictionary.

It's unfortunate that the terms have been bastardized by the popular media. Once upon a time, a "hacker" was merely somebody who refused to believe that "it can't be done" -- they'd hack away at the problem until they found a solution. You know, people like Steve Wozniak, who managed to create the Apple and Apple ][ computers by eliminating nearly half of the chips that were absolutely, positively required to make a functioning machine but would have put the price of the machine out of a hobbyist's range.

Even today, the term "hacker" has a very different meaning in the community that calls themselves by that name than it does to the talking heads on the news. I point you to Paul Graham's community news site for startups as an example. (PG "made his bones" by essentially inventing practical eCommerce, writing an application that went on to become Yahoo! Stores in Lisp, which allowed him to keep so far ahead of the competiton that they were the only player of any consequence in the game for a very long time.)

I proudly call myself a hacker, and have never attacked any site or program that I didn't create myself (or wasn't being paid to test). I've just refused to accept the "limitations" of the platform I was working on. And I've actually gotten a "Kewl -- I didn't know you could do that" from developers who created the platform my application was running on on more than one occasion.

And if there's a bit of looking down going on, well, that's directed at a couple of classes of people. Noobs can be tolerated for a while, and most will eventually learn that their questions have already been answered -- and that it's quicker to Google or RTFM than it is to post to a forum or mailing list and hope somebody answers them. The second group is a little more problematic, and I've dealt with more than a few of them over the years -- "professional" programmers (people who are employed and actually collecting paychecks) who continually ask other people to write their code for them. (I ranted about that on my blog some years ago, not long before I had my first stroke in a series.)

In most communities, there are a relatively small number of people answering the majority of questions. I think I'm still the all-time leader on the IBM Lotus developerWorks boards (with something on the order of 20,000 postings to my name -- and only three of those were questions). When you start to see the same questions popping up several times a day, there's nothing to attribute it to except laziness. It's not even about not knowing how to search when you can see your question already posted fourth from the top on the forum home page.

By the way, the "smart questions" link is on the registration page of all of the IBM forums as well.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
The problems lies in the call to ImageTTFText (which PHPlot::processTextTTF is based on). With what's installed on X10, there are misplacements at every angle from 0º to 90º (in the linked image, note the positioning of the parentheses and equals sign at 0º; see attachment for source). If you want to play with the angle, go to http://libertatia.co.cc/test/mrfish/ytitle?a=$angle. The GD extension isn't built with support for type 1 fonts, so I couldn't test ImagePSText.

It's fairly safe to say now that Freetype 2.2.11 is the culprit. It's likely that it was downgraded (I'm not certain what version was installed previously, so I can't say for certain), and it's not the only thing. For example, python is now version 2.4.3, whereas version 2.6.4 was once installed. A post in Feedback & Suggestions is in order.

As a workaround, you could create a separate image containing the vertical text, rotate that image an overlay it onto the graph. This works fine when rotating 90º, but at other angles the rotated text is quite messy. Example (test it at http://libertatia.co.cc/test/mrfish/ytitle?a=$angle):
PHP:
<?php

$font = array(
    'Courier New Bold' => 'Courier New Bold.ttf',
    'Times New Roman' => 'times.ttf',
    'Verdana' => 'verdana.ttf'
);

$wid=400;
$hite=400;
$fontSize=12;

$angle=90;
foreach (array('a', 'angle', 'theta') as $key) {
    if (isset($_REQUEST[$key])) {
        $angle = $_REQUEST[$key];
        break;
    }
}

$text = "time (seconds)";
foreach (array('t', 'text', 'm', 'msg') as $key) {
    if (isset($_REQUEST[$key])) {
        $text = $_REQUEST[$key];
        break;
    }
}

// At various points, the width of $text in pixels is approximated as strlen($text) * $fontSize

$titleX=2*$fontSize;
$titleY=($hite/2) + (strlen($text) * $fontSize / 2);

// $img is the image to output. $title will be rotated & laid over $img
$img = ImageCreateTrueColor($wid, $hite);
$title = ImageCreateTrueColor($hite, $wid);

// in creating colors, set the BG of $title to transparent
$white = ImageColorAllocate($img, 0xFF, 0xFF, 0xFF);
$fg = ImageColorAllocate($title, 0x0, 0xCF, 0xCF);
$trans = ImageColorAllocateAlpha($title, 0, 0, 0, 0);
ImageColorTransparent($title, $trans);
ImageFill($title, 0,0, $trans);

// write some explanatory text and the rotated title (for comparison) to img
ImageTTFText($img, $fontSize, 0, $fontSize+2, $fontSize+2, $white, $font['Courier New Bold'], "angle: $angle; (" . ($wid-$titleX) . ", $titleY)");
ImageTTFText($img, $fontSize, $angle, $wid - $titleX - strlen($text)*$fontSize*cos(deg2rad($angle)), $titleY, $white, $font['Courier New Bold'], $text);

// write non-rotated title to $title, then rotate the whole image & overlay $title onto $img
ImageTTFText($title, $fontSize, 0, $hite - $titleY, $titleX, $fg, $font['Courier New Bold'], $text);
$ttl = ImageRotate($title, $angle, $trans, True);
ImageDestroy($title);
$title = $ttl;
ImageCopyMerge($img, $title, 0,0, 0,0,$wid,$hite, 100);
ImageDestroy($title);

header('Content-type: image/png');

ImagePNG($img);
ImageDestroy($img);

?>

Extending PHPlot and overriding PHPlot::processTextTTF should be fairly simple, though the new implementation will be a little unsightly. I also can't think of a clean, reliable way right now to have the child class switch to using just the parent method if FreeType is upgraded (there is one messy method of questionable reliability, but I hesitate to mention it for various reasons).
 

Attachments

  • mrfish.zip
    3.9 KB · Views: 7

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Maybe it's not calling the same GD binary ?
Indeed. PHP's GD extension usually uses its own statically linked GD library, rather than what's installed system wide. The Perl GD library links to the dynamic system GD library. Both, however, use the system FreeType library.

I'm still working on Misson's advice, to try a more recent
PHPlot script...
A newer version of PHPlot might offer some advantage, but fixing uneven rotated text sadly isn't one of them.
 
Last edited:
Top