On Wed, Jul 2, 2025, at 11:43 PM, Anthony Sorace wrote:
> I get the argument (it's why I asked that part). But while I agree
> unix's 'file' is off the deep end (Exif data can really blow up
> reporting on jpegs, for example), "slippery slope" arguments are always
> a little suspect.
>
> (It's a useful reminder anyway. I'm mostly done adding depth and
> resolution to my 'file' for jpeg, and along the way you have to examine
> the bit that says whether it's a JFIF, EXIF, IPP Color Profile, or
> whatever. "Well I might as well print it" definitely crossed my mind,
> despite the fact that I've never once cared.)
Yeah, lots of little "might as well"s add up to a lot. :)
> And I've done things similar to your ii script before. But it's a lot
> more work for the CPU. My immediate use case driving this is figuring
> out what sorts of scaled images I want to generate for a directory of
> images on the web. For one directory with only 10 PNGs in it:
>
> :; time file $home/lib/web/image/*.png > /dev/null
> 0.00u 0.01s 0.02r file /usr/a/lib/web/image/jocelyn.x2y2o8t1.png ...
> :; time rc -c 'for (i in $home/lib/web/image/*.png) {echo -n $i'' '';
> png -9 $i >[2]/dev/null | /tmp/ii}' > /dev/null
> 1.62u 0.12s 1.76r rc -c for (i in $home/lib/web/image/*.png) {echo -n
> $i' '; png -9 $i >[2]/dev/null | /tmp/ii}
>
> That's quite a multiplier.
It is indeed, but...
> I think the alternative isn't passing through the Plan 9 image format,
> but a dedicated "imgtype" (like doctype) command that prints out more
> info about the target file, with less concern for conciseness... but a
> lot of that command would be duplicating what's already in 'file',
> which doesn't feel great, either.
Sometimes, a little duplication can save a lot of time. I've even heard of code duplication in Plan 9, though I forget where. (I remembered that there was duplication because at the time, I was kind-of obsessed with finding the causes of bloat.) A major cause of bloat is writing general-purpose code. I'd write a C program to do just what you want with the images. It'll be quicker than deciding what should go into imgtype. ;) I recently saw this *massive* discussion email about acme over what would be a 5-minute coding job in a simple editor without a file interface. Write your own code! :D
It doesn't take a lot of code to distinguish PNG and GIF, they both have very sensible magic numbers at the start of the file. They also have relatively consistent headers if I remember right, easier than JPEG. BMP has an overly short magic number, but you don't need BMP for the Web. I have no idea about webm and webp.
I actually gave up on my image code because I was trying to add image display to a program which already had a little file manager, text editing, a document creator, and a compiler! lol It was somebody else's old codebase which seemed simple until you saw it had got a bit messy over the years, and with all those different features, there were a lot of differnt little messes. I'm starting from scratch with smaller programs now. My big difference from Plan 9 is that I'm not going to make the API the UI. My equivalent to file will be able to supply a lot of data to other programs without overwhelming the user. It and many other programs will output structured data with named fields. The terminal-equivalent will default to only showing a few fields but will give the user full control.