File::...bImages(3pm)

πŸ“¦
version 1.01 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– File::Type::WebImages πŸ’–

okay bestie, so this is a Perl module β€” it ships as File::Type::WebImages in the 3pm manual, which is just fancy speak for "a Perl library page." And what does it do? It tells you what kind of web image you're looking at, using magic. Yes, literally magic. Well, "magic numbers." Same vibe, less sparkle. ✨


🌸 NAME 🌸

File::Type::WebImages β€” we determine web image file types using magic πŸͺ„


✨ SYNOPSIS ✨

Here's the whole entire vibe, no notes:

    use File::Type::WebImages 'mime_type';

    my $type_1 = mime_type($file);
    my $type_2 = mime_type($data);

That's it. That's the whole API. Queen behavior honestly. πŸ‘‘


πŸ’… DESCRIPTION πŸ’…

so mime_type() is the main character here, and it's lowkey flexible β€” you can hand it either a filename, or the file contents themselves, and it'll figure out the type of file for you either way.

The way it does this? It peeks at the data right at the beginning of the file. Those little opening bytes are sometimes called "magic numbers", which is such a good name, iykyk. 🧚


🌈 THE BIG TRADE OFF 🌈

okay so here's the deal, and we're being fr fr about it: this module is built for minimum memory consumption. That means it does NOT do everything. It only knows about these four common web image file types:

  • BMP
  • GIF
  • JPEG
  • PNG

and the mime types it returns for those are, in order: image/bmp, image/gif, image/jpeg and image/png. πŸ“Έ

Now for the differences from its cousins, because this is where it gets spicy:

  • Unlike File::Type and File::MMagic, when something is an unknown format, you get back 'undef' β€” NOT "application/octet-stream". So like... check your return values, bestie. Don't get caught out. 😭
  • Unlike File::Type, we return "image/png" for PNGs, not "image/x-png". We're correct about it, and we're not sorry. πŸ’…

And if you want a whole bunch more mime types detected? Then use File::Type or some other module, because that's simply not what this one is for. No hard feelings. 🫢


πŸŽ€ TODO πŸŽ€

The dream (iconic, honestly) would be a pluggable system β€” one where you could plug in different sets of MIME-types, the specific ones you actually care about. Not built yet. Manifesting though. πŸ™ˆ


πŸ¦‹ SEE ALSO πŸ¦‹

  • File::Type. Similar vibe, but it supports over 100 file types. Overachiever. We love her for it.

⭐ ACKNOWLEDGMENTS ⭐

File::Type::WebImages is built from a mime-magic file from cleancode.org. The original lives here, and yes we're crediting it properly because we're not thieves:

<http://cleancode.org/cgi-bin/viewcvs.cgi/email/mime-magic.mime?rev=1.1.1.1>


πŸ‘‘ AUTHORS πŸ‘‘

  • Paul Mison <pmison@fotango.com> β€” wrote original File::Type
  • Mark Stosberg <mark@summersault.com> β€” hacked up this.

Two legends. One module. 🫢


Copyright 2003-2004 Fotango Ltd.


🌸 LICENSE 🌸

Licensed under the same terms as Perl itself. Periodt. ✨


okay that's the whole page, bestie!! and just so you have receipts: this was perl v5.36.0, dated 2022-10-13, from the File::...bImages(3pm) page (the header truncates the name, which is so rude of it, but you get it). go forth and detect your images πŸ’–πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from