File::...bImages(3pm)
π 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::TypeandFile::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 originalFile::Type - Mark Stosberg
<mark@summersault.com>β hacked up this.
Two legends. One module. π«Ά
π COPYRIGHT π
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
- ubuntu noble: libfile-type-webimages-perl 1.01-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libfile-type-webimages-perl 1.01-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libfile-type-webimages-perl 1.01-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms