Image::Info::SVG(3)

πŸ’– Image::Info::SVG πŸ’–

okay so bestie, welcome to Image::Info::SVG, the little module that gives Image::Info its SVG support ✨ this page is from the User Contributed Perl Documentation, and honestly? it's giving "small but mighty" πŸŽ€


🌸 NAME 🌸

Image::Info::SVG β€” SVG support for Image::Info. that's it, that's the whole name, and it ate πŸ’…


✨ SYNOPSIS ✨

here's the vibe check β€” grab your info, check for errors, then go get that title:

use Image::Info qw(image_info dim);

my $info = image_info("image.svg");
if (my $error = $info->{error}) {
    die "Can't parse image info: $error\n";
}
my $title = $info->{SVG_Title};

my($w, $h) = dim($info);

like, image_info does the heavy lifting, dim gets you the dimensions, and you're living your best life πŸ¦‹


πŸ’œ DESCRIPTION πŸ’œ

so this module supplies all the standard key names β€” except these ones, which it does not provide: BitsPerSample, Compression, Gamma, Interlace, LastModificationTime. not a vibe, but okay 😭

plus it gives you these extra keys:

  • ImageDescription β€” the image description, corresponds to <desc> πŸ’¬
  • SVG_Image β€” a scalar or a reference to an array of scalars containing the URI's of embedded images (JPG or PNG) that are embedded in the image πŸ–ΌοΈ
  • SVG_StandAlone β€” whether or not the image is standalone 🧍
  • SVG_Title β€” the image title, corresponds to <title> πŸ‘‘
  • SVG_Version β€” the URI of the DTD the image conforms to πŸ“œ

πŸ”₯ METHODS πŸ”₯

process_file()

$info->process_file($source, $options);

processes one file and sets the found info fields in the $info object. one file, one job, main character energy ⭐


🧚 FILES 🧚

this module requires either XML::LibXML::Reader or XML::Simple. pick your fighter, bestie πŸ₯Š


🌈 COMPATIBILITY 🌈

okay so history lesson time, because this part is actually kind of iconic πŸ“š

previous versions (until Image-Info-1.28) used XML::Simple as the underlying parser. since Image-Info-1.29 the default parser is XML::LibXML::Reader, which is much more faster, memory-efficient, and does not rely on regular expressions for some aspects of XML parsing. periodt πŸ’…

if for some reason you need the old parser, you can force it by setting the variable @Image::Info::SVG::PREFER_MODULE as early as possible:

use Image::Info;
@Image::Info::SVG::PREFER_MODULE = qw(Image::Info::SVG::XMLSimple Image::Info::SVG::XMLLibXMLReader);

the variable $Image::Info::SVG::USING_MODULE can be queried to see which parser is in use (after Image::Info::SVG is required) πŸ‘€

since 1.38_50 processing of XML external entities (XXE) is not done anymore for security reasons in both backends (Image::Info::SVG::XMLLibXMLReader and Image::Info::SVG::XMLSimple) πŸ›‘οΈ

controlling XXE processing behavior in XML::Simple is not really possible (see https://rt.cpan.org/Ticket/Display.html?id=83794), so as a workaround the underlying SAX parser is fixed to XML::SAX::PurePerl, which is uncapable of processing external entities β€” but unfortunately it is also a slow parser 😭 like, safe but sluggish. trade-offs, fr fr πŸ’€


🫢 SEE ALSO 🫢

  • Image::Info
  • XML::LibXML::Reader
  • XML::Simple
  • XML::SAX::PurePerl

go read those if you want the full lore iykyk πŸ“–


πŸ“ NOTES πŸ“

for more information about SVG see http://www.w3.org/Graphics/SVG/ 🌐

random notes (yes, these are literally the notes, they're giving brainstorm-at-2am energy and i respect it πŸ™ˆ):

Colors
  # iterate over polygon,rect,circle,ellipse,line,polyline,text for style->stroke: style->fill:?
  #  and iterate over each of these within <g> too?! and recurse?!
  # append <color>'s
  # perhaps even deep recursion through <svg>'s?
ColorProfile <color-profile>
RenderingIntent ?
requiredFeatures
requiredExtensions
systemLanguage

πŸ’€ AUTHOR πŸ’€

Jerrad Pierce <belg4mit@mit.edu>/<webmaster@pthbb.org> wrote the original code based on XML::Simple 🫑

Slaven Rezic <srezic@cpan.org> wrote the code using XML::LibXML::Reader 🫑

this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself πŸ’–


and that's the whole page, bestie! this cutie was brought to you by perl v5.42.0, dated 2024-03-08, and it's the Image::Info::SVG(3) manpage β€” go forth and parse those SVGs, you absolute icon πŸ‘‘βœ¨πŸŽ€

πŸ“¦ where this page comes from