in reply to Re^3: How to improve image resolution
in thread How to improve image resolution...Continued

Hi BrowserUk,

Thanks for the posting. I tired this earlier but was puzzled to see the white background converting to black. Thought I was commiting some blunder. Apart from this I dint see any change in the resolution or the color (annoyingly, red appears as orange, pink as violet etc)

Replies are listed 'Best First'.
Re^5: How to improve image resolution
by BrowserUk (Patriarch) on Aug 06, 2005 at 06:13 UTC

    It sounds like you are (still) using palettized colours in conjunction with your (now) truecolor image?

    Rather than continue this guessing game, is it possible for you to post an example of the code that is producing unsatisfactory images? It would save much time.


    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.
      Thanks for the message. Sorry for not posting the code immediately due to the time difference. The essence of the code is to generate triangles on a given line dynamically based on the input file. These triangle are 3 pixel in the base and height. The problem I am having is that the slope of the triangle is not smooth (can this problem be related to my screen resolution?). Also the image does not appear to be sharp. The code runs into several hundered lines and I will put the relavant code
      use GD; $im = new GD::Image(1000,100,1); print $im->png(0);
        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.