0x09 / resdet

Detect source resolution of upscaled images
GNU Lesser General Public License v2.1
234 stars 10 forks source link

Client Buffer Support #2

Closed webbrandon closed 5 years ago

webbrandon commented 7 years ago

I wanted to see if we could get a thumbs up on adding a feature for reading buffer input for the client and not the file location.

0x09 commented 7 years ago

This is actually possible if configured with --disable-libmagic as long as the MagickWand libs from ImageMagick are available. In that case things like this will work:

convert image.png -resize 200% - | resdet /dev/stdin

libmagic provides filetype detection, but MagickWand (unrelated) does this on its own. For resdet, libmagic is most useful in environments where MagickWand isn't available and where you don't trust the filename to be accurate, such as on a server processing web uploads. It's not so important for dealing with known files on the command line.

The reason streams don't work out of the box with libmagic is that libmagic needs to peek at the file's contents before sending it to the correct image reader, but those bytes can't be put back onto the standard input once read. Solutions to this are to read the entire file into a buffer and decode the image from the buffer after probing it or, to bypass it entirely by providing some kind of out of band specification of the image type such as a separate parameter.

But until one of those is implemented just disabling libmagic and using /dev/stdin as the file argument will do the trick.

webbrandon commented 7 years ago

👍 Thank you for the details. I will try piping for now.

0x09 commented 5 years ago

As of https://github.com/0x09/resdet/commit/745fe8a752d504d2f5aa285511794f5d9c0b0afc all image readers now work with pipe inputs in all configurations, which I believe means this ticket can be closed, but feel free to re-open if I'm missing something.