[Bioperl-l] Bio::Graphics transparent background

Jonathan Crabtree jonathancrabtree at gmail.com
Thu Sep 13 09:09:56 EDT 2007

Hi Nathan-

One problem with your proposed solution is that it won't necessarily work
when GD::SVG is being used instead of GD (i.e., via the image_class method
of Bio::Graphics::Panel).  SVG doesn't handle transparency in the same way
as GD.  At least when you're compositing multiple SVG images/documents,
transparency is the default; if you superimpose one SVG image on another (
e.g., by merging the two into a single SVG document) then the bottom image
will be visible through any area of the top image that has not been drawn
on.  When I'm working in SVG with Bio::Graphics I get a "transparent"
background by simply not setting the bgcolor; this ensures that
Bio::Graphics::Panel will refrain from drawing a filled background rectangle
underneath the drawing area.  What I don't know is how to ensure that the
background is transparent when you're working with the various methods of
embedding SVG in web pages ( i.e., transparent with respect to whatever is
_underneath_ the SVG-rendered content); this is probably a slightly
different issue that's more a question of what the browser/plugin supports.

I'm not sure what to suggest as an alternative, but at the very least this
probably warrants a YMMV comment in the documentation for the new method, or
perhaps it could even throw a runtime error if called when the $gd object is
of type GD::SVG.  A final option would be to say that this (setting a
transparent background) is something that should get handled outside of
Bio::Graphics::Panel; I don't think there's any technical reason why the
calling code couldn't be responsible for this.  I don't think we can modify
your new method to unset the bgcolor when working with GD::SVG, because that
might affect the image in other ways.  I do it in my code but I'm not sure
it's 100% safe, since I think GD::SVG might actually _use_ the bgcolor in
some situations (e.g., drawing dashed lines) and I haven't checked the code
thoroughly to make sure that there are no unintended consequences.


p.s. I see that Chris has beaten me to the punch in mentioning SVG as a fix
to your blocky font problems.  All the more reason to think about how this
feature will work in that context!

On 9/13/07, Nathan Haigh <n.haigh at sheffield.ac.uk > wrote:
> Nathan Haigh wrote:
> > Kevin Brown wrote:
> >
> >>> Is it possible to set the bg colour of glyphs and the panel
> >>> background to be transparent? If so, which output formats
> >>> support transparency?
> >>>
> >>>
> >> Not sure if you can, but SVG, PNG, Gif all support a transparent
> >> background.
> >>
> >> _______________________________________________
> >> Bioperl-l mailing list
> >> Bioperl-l at lists.open-bio.org
> >> http://lists.open-bio.org/mailman/listinfo/bioperl-l
> >>
> >>
> >
> > Looking at the GD module documentation:
> > http://search.cpan.org/~lds/GD-2.30/GD.pm
> <http://search.cpan.org/%7Elds/GD-2.30/GD.pm>
> >
> > It appears that you can set a colour as being transparent - so I think
> > it should be possible to get Bio::Graphics to do this = may require some
> > code to be written. Any one got ideas?
> >
> > Cheers,
> > Nath
> > _______________________________________________
> > Bioperl-l mailing list
> > Bioperl-l at lists.open-bio.org
> > http://lists.open-bio.org/mailman/listinfo/bioperl-l
> >
> I took a look and made a simple change to Bio::Graphics::Panel
> Please see the following bug for a patch and explanation:
> http://bugzilla.open-bio.org/show_bug.cgi?id=2365
> I'd appreciate any comments, especially regarding the method name! If
> there aren't any complaints I'll commit it later today.
> Nath
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l

More information about the Bioperl-l mailing list