The problem I am having is that the slope of the triangle is not smooth

The problem you are seeing is an inherent effect of digital images often referred to as "the jaggies".

The technique to lessen the apparent jagginess is called AntiAliasing. Recent versions of GD have support for antialiasing built-in, but they require the programmer to use them. This basically consists of using setAntiAliased( $color ) to set the color you wish to draw in and then passing gdAntiAliased in place of the color on the actual drawing primative. A simple demonstration of using them:

#! perl -slw use strict; use GD; our $X ||= 500; our $Y ||= 500; my $img = new GD::Image( 2*$X, $Y, 1 ); my $white = $img->colorAllocate( 255, 255, 255 ); my $black = $img->colorAllocate( 0, 0, 0 ); $img->filledRectangle( 0,0, $img->getBounds, $white ); ## No anti-aliasing for my $y ( map{ $_ * 20 } 0 .. $Y/ 20 ) { $img->line( 0, 0, $X, $y, $black ); } for my $x ( map{ $_ * 20 } 0 .. $X/20 ) { $img->line( 0, 0, $x, $Y, $black ); } ## Same thing antialiased $img->setAntiAliased( $black ); for my $y ( map{ $_ * 20 } 0 .. $Y/20 ) { $img->line( $X, 0, 2*$X, $y, gdAntiAliased ); } for my $x ( map{ $_ * 20 } 0 .. $X/20 ) { $img->line( $X, 0, $X+$x, $Y, gdAntiAliased ); } open PNG, '>:raw', 'test.png' or die $!; print PNG $img->png( 9 ); close PNG; system "test.png"; ## Adjust to start your favourite picture viewer.

The left-hand half of the image is drawn without antialiasing, the right-hand half with.

I'm not convinced that libgd's antialiasing algorithm is the best around, but it does make a difference.

BTW. As you appear to have made the transition from using gifs to pngs, there is no reason not to use full compression $img->png( 9 ); when saving your pngs to disk.

Being a non-lossy algorithm the compression doesn't affect the quality of the image as it does with jpgs, and it saves a huge amount of disk space.

It will take a few milliseconds longer to decompress the images, but generally, the time saved loading the compressed image into memory (especially across the network) will more than compensate for the extra time spent decompressing it.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

In reply to Re^7: How to improve image resolution by BrowserUk
in thread How to improve image resolution...Continued by chakkaln

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.