graphics

Discussion in 'Perl Misc' started by Huub, Jun 9, 2010.

  1. Huub

    Huub Guest

    Hi,

    I'm using Perl to print from database, which works great. Now I'd like to
    print a .JPG picture with it. However, searching CPAN I find a LOT of
    graphics modules. Any recommendation which one to use for this?

    Thanks.
     
    Huub, Jun 9, 2010
    #1
    1. Advertising

  2. On Wed, 09 Jun 2010 04:40:45 +0000, Huub wrote:

    > Hi,
    >
    > I'm using Perl to print from database, which works great. Now I'd like
    > to print a .JPG picture with it. However, searching CPAN I find a LOT of
    > graphics modules. Any recommendation which one to use for this?


    I'm looking into something similar right now. After searching CPAN, I
    looked better at CD::Graph and Chart and found both very similar, and
    lacking for my purpose. They are good though.

    I then looked at driving gnuplot from perl, and it will probably serve
    your needs. It's incredible what you can do with gnuplot.

    It still didn't need my needs (for every x-pixel, draw min, max and avg)
    so I'm currently deriving from GD::axestype to do it myself.

    HTH,
    M4
     
    Martijn Lievaart, Jun 9, 2010
    #2
    1. Advertising

  3. Huub <v.niekerk_@_hccnet.nl> wrote:
    >I'm using Perl to print from database, which works great. Now I'd like to
    >print a .JPG picture with it.


    I am puzzled.

    "print" like in print to a sheet of paper? Normally you would use
    whatever means your OS provides for that and normally yes, you could
    initiate that via a Perl program, too, just like you would initiate any
    other external command from a Perl program.

    Or "print" like the print() function in Perl? Well, that is mostly for
    text although of course you can use it for binary data, too.

    Or what "print" are you talking about?

    jue
     
    Jürgen Exner, Jun 9, 2010
    #3
  4. Huub

    Huub Guest

    On Wed, 09 Jun 2010 07:34:10 -0700, Jürgen Exner wrote:

    > Huub <v.niekerk_@_hccnet.nl> wrote:
    >>I'm using Perl to print from database, which works great. Now I'd like
    >>to print a .JPG picture with it.

    >
    > I am puzzled.
    >
    > "print" like in print to a sheet of paper? Normally you would use
    > whatever means your OS provides for that and normally yes, you could
    > initiate that via a Perl program, too, just like you would initiate any
    > other external command from a Perl program.
    >
    > Or "print" like the print() function in Perl? Well, that is mostly for
    > text although of course you can use it for binary data, too.
    >
    > Or what "print" are you talking about?
    >
    > jue


    Ok, looks like I haven't been clear enough.

    I am talking about printing to paper and the intention is to print an
    existing jpg picture on the paper after which the data from the database
    is printed.

    Reading the other reactions, I think it would be easier to first print
    that image using Gimp or so, and then re-use the paper using Perl to
    print the data. Though it would take at least twice as much time.

    Any suggestion welcome.
     
    Huub, Jun 9, 2010
    #4
  5. Huub

    Willem Guest

    Huub wrote:
    ) Ok, looks like I haven't been clear enough.
    )
    ) I am talking about printing to paper and the intention is to print an
    ) existing jpg picture on the paper after which the data from the database
    ) is printed.
    )
    ) Reading the other reactions, I think it would be easier to first print
    ) that image using Gimp or so, and then re-use the paper using Perl to
    ) print the data. Though it would take at least twice as much time.

    What method are you using to print the data to the printer ?
    Are you using some module ? Is it pure plain text ? Postscript ?

    There's probably some Perl module out there that can print combined
    text and jpg images to a printer.


    SaSW, Willem
    --
    Disclaimer: I am in no way responsible for any of the statements
    made in the above text. For all I know I might be
    drugged or something..
    No I'm not paranoid. You all think I'm paranoid, don't you !
    #EOT
     
    Willem, Jun 9, 2010
    #5
  6. On 09/06/2010 05:40, Huub wrote:
    >
    > I'm using Perl to print from database, which works great.


    So how are you doing that? You might be

    * Using a Win32 API to make GDI calls etc
    * Using Perl print() statements to write a text file
    then exec() a 'lp' command
    * A gazillion other possibilities.

    In order to provide a relevant answer, potential helpers might benefit
    from a little more context.

    > Now I'd like to
    > print a .JPG picture with it. However, searching CPAN I find a LOT of
    > graphics modules. Any recommendation which one to use for this?


    I'd have the Perl program write a Postscript file containing image data
    and text, then use OS-dependant commands to spool that to a Postscript
    printer or via a Postscript aware print subsystem like CUPS or
    Ghostscript. Your mileage is likely to vary. CPAN is your friend.

    --
    RGB
     
    RedGrittyBrick, Jun 9, 2010
    #6
  7. Huub

    John Bokma Guest

    Huub <v.niekerk_@_hccnet.nl> writes:

    > On Wed, 09 Jun 2010 07:34:10 -0700, Jürgen Exner wrote:
    >
    >> Huub <v.niekerk_@_hccnet.nl> wrote:
    >>>I'm using Perl to print from database, which works great. Now I'd like
    >>>to print a .JPG picture with it.

    >>
    >> I am puzzled.
    >>
    >> "print" like in print to a sheet of paper? Normally you would use
    >> whatever means your OS provides for that and normally yes, you could
    >> initiate that via a Perl program, too, just like you would initiate any
    >> other external command from a Perl program.
    >>
    >> Or "print" like the print() function in Perl? Well, that is mostly for
    >> text although of course you can use it for binary data, too.
    >>
    >> Or what "print" are you talking about?
    >>
    >> jue

    >
    > Ok, looks like I haven't been clear enough.
    >
    > I am talking about printing to paper and the intention is to print an
    > existing jpg picture on the paper after which the data from the database
    > is printed.
    >
    > Reading the other reactions, I think it would be easier to first print
    > that image using Gimp or so, and then re-use the paper using Perl to
    > print the data. Though it would take at least twice as much time.
    >
    >
    > Any suggestion welcome.


    Install Java, Apache FOP, and Saxon-B XSLT
    Generate XML via your Perl program
    Convert this XML via saxonb-xslt to fo
    Convert fo to pdf (or pick any other of the formats supported) using
    Apache FOP.

    It sounds like a lot of trouble, but IMO it's extremely flexible, see:
    http://johnbokma.com/mexit/2010/02/11/

    It's most likely easier than generating your own PDF. Another option is
    to just generate a HTML file and print that one via a browser (or
    convert HTML to PDF and print that). But I am quite sure that XSL-FO
    gives you more control over the output than HTML.

    --
    John Bokma j3b

    Hacking & Hiking in Mexico - http://johnbokma.com/
    http://castleamber.com/ - Perl & Python Development
     
    John Bokma, Jun 9, 2010
    #7
  8. Huub

    Huub Guest

    On Wed, 09 Jun 2010 15:51:07 +0000, Willem wrote:

    > Huub wrote:
    > ) Ok, looks like I haven't been clear enough. )
    > ) I am talking about printing to paper and the intention is to print an
    > ) existing jpg picture on the paper after which the data from the
    > database ) is printed.
    > )
    > ) Reading the other reactions, I think it would be easier to first print
    > ) that image using Gimp or so, and then re-use the paper using Perl to )
    > print the data. Though it would take at least twice as much time.
    >
    > What method are you using to print the data to the printer ? Are you
    > using some module ? Is it pure plain text ? Postscript ?
    >
    > There's probably some Perl module out there that can print combined text
    > and jpg images to a printer.
    >
    >
    > SaSW, Willem


    I use DBI to get the data from the database, after which it is printed as
    pure plain text. So I'm not converting anything to XML, HTML, pdf or so.
    This has worked for some years now, and no problem.

    And my initial question was if there is a Perl module that enables me to
    print both a jpg image and the data from the database in 1 single
    printjob. But if I understood it correctly, the Graphics modules are
    intended to create a graphical image, rather than to fetch one for e.g.
    printing on paper.
     
    Huub, Jun 9, 2010
    #8
  9. Huub

    Willem Guest

    Huub wrote:
    ) I use DBI to get the data from the database, after which it is printed as
    ) pure plain text. So I'm not converting anything to XML, HTML, pdf or so.
    ) This has worked for some years now, and no problem.
    )
    ) And my initial question was if there is a Perl module that enables me to
    ) print both a jpg image and the data from the database in 1 single
    ) printjob. But if I understood it correctly, the Graphics modules are
    ) intended to create a graphical image, rather than to fetch one for e.g.
    ) printing on paper.

    Yes, you want a printing module for that, not a graphics module.

    For example, on Win32 you have stuff like Win32::printer, which can
    print several image formats, according to the docs.

    Or you could generate HTML or XSL-FO or something with the text
    and the graphics you want, and then print that.


    SaSW, Willem
    --
    Disclaimer: I am in no way responsible for any of the statements
    made in the above text. For all I know I might be
    drugged or something..
    No I'm not paranoid. You all think I'm paranoid, don't you !
    #EOT
     
    Willem, Jun 9, 2010
    #9
  10. Huub

    Steve C Guest

    Huub wrote:
    > Hi,
    >
    > I'm using Perl to print from database, which works great. Now I'd like to
    > print a .JPG picture with it. However, searching CPAN I find a LOT of
    > graphics modules. Any recommendation which one to use for this?
    >


    The intermediate form between binary data and a printer is a
    page description language. ASCII is the original text-only PDL,
    but you can't use it for anything more complex.

    Good choices for page description with images are postscript, pdf,
    or pcl, all of which can be generated from perl. HTML works too if
    value ease over precision. It just depends on your printing
    environment.
     
    Steve C, Jun 9, 2010
    #10
  11. On 2010-06-09, RedGrittyBrick <> wrote:
    > I'd have the Perl program write a Postscript file containing image data
    > and text, then use OS-dependant commands to spool that to a Postscript
    > printer or via a Postscript aware print subsystem like CUPS or
    > Ghostscript. Your mileage is likely to vary. CPAN is your friend.


    Nowadays it looks like PostScript would be the last choice...
    Generating PDF might be easy (did not try it), and it is much easier
    to print...

    Myself, I would go through enscript or TeX - this would cover the
    typesetting needs (instead of trying to reinvent things in Perl).

    Hope this helps,
    Ilya
     
    Ilya Zakharevich, Jun 10, 2010
    #11
  12. Huub

    John Bokma Guest

    Ilya Zakharevich <> writes:

    > On 2010-06-09, RedGrittyBrick <> wrote:
    >> I'd have the Perl program write a Postscript file containing image data
    >> and text, then use OS-dependant commands to spool that to a Postscript
    >> printer or via a Postscript aware print subsystem like CUPS or
    >> Ghostscript. Your mileage is likely to vary. CPAN is your friend.

    >
    > Nowadays it looks like PostScript would be the last choice...
    > Generating PDF might be easy (did not try it), and it is much easier
    > to print...
    >
    > Myself, I would go through enscript or TeX - this would cover the
    > typesetting needs (instead of trying to reinvent things in Perl).
    >
    > Hope this helps,
    > Ilya


    Over a year ago I played with lout:
    http://en.wikipedia.org/wiki/Lout_(software)

    Maybe also something to look into?

    --
    John Bokma j3b

    Hacking & Hiking in Mexico - http://johnbokma.com/
    http://castleamber.com/ - Perl & Python Development
     
    John Bokma, Jun 10, 2010
    #12
  13. On 10/06/2010 03:08, Ilya Zakharevich wrote:
    > On 2010-06-09, RedGrittyBrick<> wrote:
    >> I'd have the Perl program write a Postscript file containing image data
    >> and text, then use OS-dependant commands to spool that to a Postscript
    >> printer or via a Postscript aware print subsystem like CUPS or
    >> Ghostscript. Your mileage is likely to vary. CPAN is your friend.

    >
    > Nowadays it looks like PostScript would be the last choice...


    I think it depends on your skillset, I happen to know a little
    PostScript and like the language a lot, this obviously biases my choice.


    > Generating PDF might be easy (did not try it),


    Yes, there appear to be some good CPAN modules for writing PDF.


    > and it is much easier to print...


    This isn't something I find any problems with. Most laser printers above
    entry level will support PostScript printing. Some of them support PDF
    printing. Most (if not all) Unix/Linux systems will have print systems
    that can rasterise PostScript for non-Postscript printers.


    > Myself, I would go through enscript or TeX - this would cover the
    > typesetting needs


    I also use enscript and a2ps. I found writing TeX (or rather LaTeX)
    still needs a lot of markup and the production chain can be complicated
    and prone to generating mysterious error messages. What TeX toolset do
    you use?

    I use grutatxt a lot - which can generate HTML and LaTeX (and thence
    PDF) from plain text. It is available as a Perl module. I'm not sure
    about the inclusion of images other than for HTML though. I certainly
    prefer keeping source matter in a plain text form rather than in any
    proprietary form that is likely to become obsolete and unreadable.

    The OP might look at these as well as markdown, asciidoc etc


    > (instead of trying to reinvent things in Perl).


    That is a good point. It depends a bit on how much "typesetting" you
    need to do but I guess I must agree.

    --
    RGB
     
    RedGrittyBrick, Jun 10, 2010
    #13
  14. RedGrittyBrick <> writes:

    > On 10/06/2010 03:08, Ilya Zakharevich wrote:
    >> Myself, I would go through enscript or TeX - this would cover the
    >> typesetting needs

    >
    > I also use enscript and a2ps. I found writing TeX (or rather LaTeX)
    > still needs a lot of markup and the production chain can be
    > complicated and prone to generating mysterious error messages. What
    > TeX toolset do you use?
    >


    Not speaking for Ilya, but at work I had to write something to generate
    reports. I used SVG::TT:Graph to generate the graphs, Image::Magick to
    convert them to PNG, Template Toolkit to build LaTex files referring to
    the images, and LaTeX::Driver to render the LaTeX to PDF.

    Works like a charm, even if the toolchain is long. LaTeX::Driver is a
    bit finicky if you don't clean up your working directory though.

    Mart

    --
    "We will need a longer wall when the revolution comes."
    --- AJS, quoting an uncertain source.
     
    Mart van de Wege, Jun 10, 2010
    #14
  15. On 2010-06-10, RedGrittyBrick <> wrote:
    >> Generating PDF might be easy (did not try it),


    > Yes, there appear to be some good CPAN modules for writing PDF.


    >> and it is much easier to print...


    > This isn't something I find any problems with. Most laser printers above
    > entry level will support PostScript printing. Some of them support PDF
    > printing. Most (if not all) Unix/Linux systems will have print systems
    > that can rasterise PostScript for non-Postscript printers.


    You have a wrong (IMO) metric of "having problems". PS is a
    programming language. There is no way to "verify" PS or debug PS:
    there is no way to know whether a given PS file will print on your
    neighbor's PS printer except for printing it.

    Likewise, if you can rasterize PS with one version of GS, this does
    not imply that it would rasterize with a different version of GS.
    Basically, PS leads you in the same messy can of worms as most other
    programming languages (only it has no debuggers or development tools).

    PDF, on the other hand, contains just DATA, not PROGRAM. It must be
    easy to verify (never tried it); then any non-buggy implementation
    would be able to rasterize it.

    >> Myself, I would go through enscript or TeX - this would cover the
    >> typesetting needs

    >
    > I also use enscript and a2ps. I found writing TeX (or rather LaTeX)
    > still needs a lot of markup and the production chain can be complicated
    > and prone to generating mysterious error messages. What TeX toolset do
    > you use?


    LaTeX + ams.

    > prefer keeping source matter in a plain text form rather than in any
    > proprietary form that is likely to become obsolete and unreadable.


    It is exactly the opposite with me. LaTeX is known to be
    non-backward-compatible. So I keep data in proprietary form with a
    known script for to-LaTeX conversion. When backward-compatibility
    breaks, I can compensate by editing the scripts...

    Yours,
    Ilya
     
    Ilya Zakharevich, Jun 11, 2010
    #15
  16. Huub

    Ted Zlatanov Guest

    On Thu, 10 Jun 2010 22:37:56 +0200 Mart van de Wege <> wrote:

    MvdW> I used SVG::TT:Graph to generate the graphs, Image::Magick to
    MvdW> convert them to PNG, Template Toolkit to build LaTex files
    MvdW> referring to the images, and LaTeX::Driver to render the LaTeX to
    MvdW> PDF.

    MvdW> Works like a charm, even if the toolchain is long. LaTeX::Driver is a
    MvdW> bit finicky if you don't clean up your working directory though.

    Any chance you can publish your toolchain to convert a series of PNG
    files to a PDF file?

    Thanks
    Ted
     
    Ted Zlatanov, Jun 11, 2010
    #16
  17. Huub

    John Bokma Guest

    Ted Zlatanov <> writes:

    > On Thu, 10 Jun 2010 22:37:56 +0200 Mart van de Wege <> wrote:
    >
    > MvdW> I used SVG::TT:Graph to generate the graphs, Image::Magick to
    > MvdW> convert them to PNG, Template Toolkit to build LaTex files
    > MvdW> referring to the images, and LaTeX::Driver to render the LaTeX to
    > MvdW> PDF.
    >
    > MvdW> Works like a charm, even if the toolchain is long. LaTeX::Driver is a
    > MvdW> bit finicky if you don't clean up your working directory though.
    >
    > Any chance you can publish your toolchain to convert a series of PNG
    > files to a PDF file?


    While most likely not an answer to your question, some time ago I wrote
    this:

    http://johnbokma.com/mexit/2009/02/24/jpeg-to-pdf-using-perl.html

    to create a pdf with one JPEG per page.

    --
    John Bokma j3b

    Hacking & Hiking in Mexico - http://johnbokma.com/
    http://castleamber.com/ - Perl & Python Development
     
    John Bokma, Jun 11, 2010
    #17
  18. Ted Zlatanov <> writes:

    > On Thu, 10 Jun 2010 22:37:56 +0200 Mart van de Wege <> wrote:
    >
    > MvdW> I used SVG::TT:Graph to generate the graphs, Image::Magick to
    > MvdW> convert them to PNG, Template Toolkit to build LaTex files
    > MvdW> referring to the images, and LaTeX::Driver to render the LaTeX to
    > MvdW> PDF.
    >
    > MvdW> Works like a charm, even if the toolchain is long. LaTeX::Driver is a
    > MvdW> bit finicky if you don't clean up your working directory though.
    >
    > Any chance you can publish your toolchain to convert a series of PNG
    > files to a PDF file?
    >

    Hmm. Sure thing, but it's in three fairly substantive package files. Do
    you want that posted here, or in a private mail?

    Also, I may have to anonymise our company name, which is referred to
    quite often in variables and directory/file names.

    So tell me, how do you want it?

    Mart

    --
    "We will need a longer wall when the revolution comes."
    --- AJS, quoting an uncertain source.
     
    Mart van de Wege, Jun 11, 2010
    #18
  19. Huub

    Dr.Ruud Guest

    Huub wrote:

    > I'm using Perl to print from database, which works great. Now I'd like to
    > print a .JPG picture with it. However, searching CPAN I find a LOT of
    > graphics modules. Any recommendation which one to use for this?


    WebKit is great for this.
    http://code.google.com/p/wkhtmltopdf/

    --
    Ruud
     
    Dr.Ruud, Jun 11, 2010
    #19
  20. On 2010-06-11 03:19, Ilya Zakharevich <> wrote:
    > On 2010-06-10, RedGrittyBrick <> wrote:
    >>> Generating PDF might be easy (did not try it),
    >>> and it is much easier to print...

    >
    >> This isn't something I find any problems with. Most laser printers above
    >> entry level will support PostScript printing. Some of them support PDF
    >> printing. Most (if not all) Unix/Linux systems will have print systems
    >> that can rasterise PostScript for non-Postscript printers.

    >
    > You have a wrong (IMO) metric of "having problems". PS is a
    > programming language. There is no way to "verify" PS or debug PS:
    > there is no way to know whether a given PS file will print on your
    > neighbor's PS printer except for printing it.
    >
    > Likewise, if you can rasterize PS with one version of GS, this does
    > not imply that it would rasterize with a different version of GS.
    > Basically, PS leads you in the same messy can of worms as most other
    > programming languages (only it has no debuggers or development tools).
    >
    > PDF, on the other hand, contains just DATA, not PROGRAM.


    There is no clear-cut boundary between data and program. True, PDF isn't
    turing-complete (unless it contains JavaScript), but that doesn't make
    the interpreter much simpler. The exclusion of flow-control from the PDF
    language has other advantages, though: For example, you can determine
    page boundaries by a static analysis of the file, which isn't possible
    in Postscript (although there is a convention to use special comments
    for that).

    > It must be easy to verify (never tried it); then any non-buggy
    > implementation would be able to rasterize it.


    Newer versions of Acrobat Reader won't rasterize some PDFs generated by
    Acrobat 10 years ago, because some features of early PDF versions have
    been removed in later versions. OTOH, I am not aware of any
    backwards-compatibility issues with PostScript (which also went through
    a lot less revisions, although it is older).


    >>> Myself, I would go through enscript or TeX - this would cover the
    >>> typesetting needs

    >>
    >> I also use enscript and a2ps. I found writing TeX (or rather LaTeX)
    >> still needs a lot of markup and the production chain can be complicated
    >> and prone to generating mysterious error messages. What TeX toolset do
    >> you use?

    >
    > LaTeX + ams.


    LaTeX (or rather TeX) is a programming language, too.

    It does have the advantage over page description languages like PDF of
    PostScript that it handles much of the layout automatically (and
    produces rather nice output).

    >> prefer keeping source matter in a plain text form rather than in any
    >> proprietary form that is likely to become obsolete and unreadable.

    >
    > It is exactly the opposite with me. LaTeX is known to be
    > non-backward-compatible. So I keep data in proprietary form with a
    > known script for to-LaTeX conversion.


    Who is the proprietor of your proprietary format? You? Then you
    naturally won't have a problem, as you know and control the format.
    Somebody else? Then you may run into problems when that person or
    company stops supporting that format or alters it in an incompatible
    way.

    hp
     
    Peter J. Holzer, Jun 13, 2010
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman

    Convert e.Graphics to an image or bitmap

    Charles A. Lackman, Jun 10, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    15,611
    logon68
    Feb 10, 2011
  2. DB
    Replies:
    1
    Views:
    1,028
    Tuukka Toivonen
    Aug 19, 2003
  3. jk
    Replies:
    1
    Views:
    549
    Mike Treseler
    Jan 4, 2004
  4. suz
    Replies:
    6
    Views:
    5,248
    Jason Zheng
    Jul 26, 2004
  5. Derek Simmons

    Primitve 3D Graphics Library

    Derek Simmons, Aug 11, 2004, in forum: VHDL
    Replies:
    1
    Views:
    510
    John Williams
    Aug 12, 2004
Loading...

Share This Page