Is there any fast way to determine if some arbitrary image file is a png file or a jpeg file or none of them?
I’m pretty sure there is some way and these files probably have some sort of their own signatures and there should be some way to distinguish them.
If possible, could you also provide the names of the corresponding routines in libpng / libjpeg / boost::gil::io.
Apart from Tim Yates’ suggestion of reading the magic number “by hand”, the Boost GIL documentation says:
png_read_imagethrowsstd::ios_base::failureif the file is not a valid PNG file.jpeg_read_imagethrowsstd::ios_base::failureif the file is not a valid JPEG file.Similarly for other Boost GIL routines. If you only want the type, you might want to try reading only the dimensions, rather than loading the entire file.