Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

GD Simple, Palette Background

by watari_exd (Initiate)
on Nov 08, 2017 at 03:41 UTC ( #1202943=perlquestion: print w/replies, xml ) Need Help??
watari_exd has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I've only recently started using GD Simple, following the tutorials out there. My question is, is there a way to color the entire image (let's call it the pallet) with a background color, so that the things you're drawing in your image appear on that background? In the tutorials, fgcolor and bgcolor appear only to apply to the pen and the things (e.g., polygons, etc.) created in the image. Also, in the examples given in the tutorials, all of such objects are printed on a non-transparent white background. Is there a solution to this? Thank you

Replies are listed 'Best First'.
Re: GD Simple, Palette Background
by roboticus (Chancellor) on Nov 08, 2017 at 05:22 UTC


    In the docs for GD::Simple, it says that the $img->clear method clears the canvas by painting over it with the current background color. So I'd expect you should simply be able to do something like:

    $img->bgcolor($your_color_variable); $img->clear(); ... the rest of your drawing code ...


    When your only tool is a hammer, all problems look like your thumb.

      That worked beautifully. Thank you! I'm not sure how I missed that.
Re: GD Simple, Image (Not Palette) Background
by hippo (Canon) on Nov 08, 2017 at 09:17 UTC
    is there a way to color the entire image (let's call it the pallet)

    Please let's not call it that. The term palette has a small number of very specific, related meanings within the realm of digitally generated images. It's a term which everyone in the field uses in those contexts. If you suddenly start to assign arbitrary new meanings to words which everyone else understands to mean something different you will only create problems for yourself. Instead, consider "image" or "canvas" depending on the subtleties of what you refer to.

    If you are new to computer generated images as well as to GD::Simple then you will have to learn the jargon as with any other new field. Good luck with your new endeavour.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1202943]
Approved by Athanasius
Front-paged by Corion
and the questions are moot...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2018-06-18 20:22 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.