Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How to increase the resoultion of an PNG image

by vinumanikandan (Initiate)
on Dec 18, 2010 at 19:01 UTC ( #877789=perlquestion: print w/ replies, xml ) Need Help??
vinumanikandan has asked for the wisdom of the Perl Monks concerning the following question:

Hi I'M using Perl GD to create an image with response to user entry and the database retrevial using the Perl GD and DBI and CGI modules. Even though i'm successful in making the png image my boss is not happy at the resoultion of the image. The code is as in below
my $im = new GD::Image(710,$Image_Height); my $white = $im->colorAllocate(255,255,255); my $black = $im->colorAllocate(0,0,0); my $blue = $im->colorAllocate(0,0,255); $im->transparent($white); $im->interlaced('true'); $im->filledRectangle($Trans_X1,$Image_Height-20,$Trans_X1,$Image_Heigh +t-10,$scale_line); ### Scale ###### $im->filledRectangle($Trans_X1+$Scale_Length,$Image_Height-20,$Tra +ns_X1+$Scale_Length,$Image_Height-10,$scale_line); ### Scale ###### $im->string(gdSmallFont,$Trans_X1,$Image_Height-32,1,$scale_line); $im->string(gdSmallFont,$Trans_X1+$Scale_Length,$Image_Height-32,$ +Length,$scale_line); open OUT,">$ID.png"; binmode OUT; # Convert the image to PNG and print it on standard output print OUT $im->png; close OUT;
Please let me know what to do to increase the resoultion of the image (above is psuedo code)

Comment on How to increase the resoultion of an PNG image
Download Code
Re: How to increase the resoultion of an PNG image
by Anonymous Monk on Dec 18, 2010 at 19:14 UTC
Re: How to increase the resoultion of an PNG image
by moritz (Cardinal) on Dec 18, 2010 at 20:02 UTC
      Dear Monk thanks for replying. The second vataiable will depen up on my deta coming from my Database and i wopnt be able to increase the same more thatn an extend as its been used in CGI script to view the image
Re: How to increase the resoultion of an PNG image
by Anonyrnous Monk (Hermit) on Dec 18, 2010 at 20:18 UTC

    Not really sure what you mean by resolution of the PNG image. As the PNG format stores pixels, the resolution of an (unscaled) image only depends on the resolution of the viewing device (such as a monitor). In other words, the trivial approach to a more detailed image would be to create a larger image, with drawing coordinates, font sizes, etc. adjusted accordingly. I suppose this occurred to you already... which is why I'm asking what you mean by resolution.

    If it's that the text/lines in the image look "ragged", you (or your boss) might actually want antialiasing, which makes the image appear smoother to the human eye (by reducing spatial sampling artifacts). GD offers gdAntiAliased color for drawing, but I think for text only TrueType fonts provide antialiasing (method stringFT()).

Re: How to increase the resoultion of an PNG image
by BrowserUk (Pope) on Dec 18, 2010 at 20:58 UTC

    You are trying, (but failing dismally). to create an 8-bit paletted image containing small-font text. These always look pretty "lo-res", as any attempt to anti-alias the fonts simply doesn't work. To produce an image that will be perceived as "high resolution"; you'll need to make it a 24-bit (truecolor) image.

    Had you posted working code, you might have got working code demonstrating how to do that as a response.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thank you , Yes i had posted the code for the review. What i am doing is making the GD work dynamical depending on the user input and corresponding output from the db and plotting it. the image width is constant and the height depends on the db output. the thus created image is loaded to th eCGI script and using the Javascript and Jquery function Im zooming into the same image.
Re: How to increase the resoultion of an PNG image
by Khen1950fx (Canon) on Dec 19, 2010 at 03:54 UTC
    open OUT,">$ID.png"; binmode OUT; print OUT $im->png; close OUT;
    That's not right. You want to print the png to STDOUT, so do something like this:
    #!/usr/bin/perl use strict; use warnings; use GD; use GD::Image; my $im_width = 1000; my $im_height = 1000; my $im = GD::Image->newTrueColor($im_width, $im_height); my $white = $im->colorAllocate(255,255,255); my $black = $im->colorAllocate(0,0,255); my $red = $im->colorAllocate(255,0,0); my $blue = $im->colorAllocate(0,0,255); $im->rectangle(0,0,99,99,$black); $im->arc(50,50,95,75,0,360,$blue); $im->fill(50,50,$red); my $pngdata = $im->png; open (DISPLAY,"| display -") || die; binmode DISPLAY; print DISPLAY $pngdata; close DISPLAY;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://877789]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-12-28 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls