+ Reply to Thread
Results 1 to 8 of 8

Thread: Little PHPlot problem

  1. #1
    cerbere is offline x10Hosting Member cerbere is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    51

    Little PHPlot problem

    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 !

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Little PHPlot problem

    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 by misson; 08-17-2010 at 09:20 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    cerbere is offline x10Hosting Member cerbere is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    51

    Re: Little PHPlot problem

    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.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Little PHPlot problem

    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).

    Quote Originally Posted by cerbere View Post
    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.

    Quote Originally Posted by cerbere View Post
    Look at "hack", "hacking", "hacker" in a dictionary.
    Such as the jargon file? :-)
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: Little PHPlot problem

    Quote Originally Posted by cerbere View Post
    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.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Little PHPlot problem

    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 Code:
    <?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($img0xFF0xFF0xFF);
    $fg ImageColorAllocate($title0x00xCF0xCF);
    $trans ImageColorAllocateAlpha($title0000);
    ImageColorTransparent($title$trans);
    ImageFill($title0,0$trans);

    // write some explanatory text and the rotated title (for comparison) to img
    ImageTTFText($img$fontSize0$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$fontSize0$hite $titleY$titleX$fg$font['Courier New Bold'], $text);
    $ttl ImageRotate($title$angle$transTrue);
    ImageDestroy($title);
    $title $ttl;
    ImageCopyMerge($img$title0,00,0,$wid,$hite100);
    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).
    Attached Files
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  7. #7
    cerbere is offline x10Hosting Member cerbere is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    51

    Re: Little PHPlot problem

    Thanks for your replies about GD/PHPlot, and your views
    on the hacking elite.

    Here is some text rotation written in perl, no anomalies.
    http://ixedix.x10hosting.com/cgi-bin/GD/TextCheck.pl
    (hit refresh for different number of rotations).

    The code is here :
    http://ixedix.x10hosting.com/TextPut.txt

    Maybe it's not calling the same GD binary ?

    I'm still working on Misson's advice, to try a more recent
    PHPlot script...

  8. #8
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Little PHPlot problem

    Quote Originally Posted by cerbere View Post
    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.

    Quote Originally Posted by cerbere View Post
    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 by misson; 08-26-2010 at 02:48 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Replies: 3
    Last Post: 07-08-2010, 01:47 AM
  2. Control Panel problem / Hosting problem
    By cgreyes in forum Free Hosting
    Replies: 1
    Last Post: 11-24-2008, 06:15 AM
  3. Problem uploading image (GD library problem)
    By HyDr@ in forum Free Hosting
    Replies: 1
    Last Post: 12-01-2006, 04:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers