How to check if a file / not an image without downloading the full file? Is there a library for reading image headers?

change

Sorry, I think my question was vague. I would like to be able to check if the file is not an image, without wasting time downloading the whole image, because then I can complete the rest of the download later. I do not want to just check the file extension.

The application simply views the images. By "validation" I meant "detecting and skipping files without an image" also in the directory. If the pixel data is damaged, I would like to treat it as an image.

I assign page numbers and put these images together. Some images are a single left or right page. Some images are wide and are “common” on the left and right pages. For example, pagesAt (3) and pagesAt (4) can return the same std :: pair of images or std :: a pair of the same widescreen image.

Sometimes an odd number of “thin” images appear, and the first image should display on its own, like a wide image. An example is a separate cover page.

Not knowing which files in the directory are not images, I cannot confidently assign these page numbers and map files for display. In addition, the user may decide to go to page X, and when I later discover and delete the file without the image and reassign the page numbers, page X may appear to be another image.

original

In case that matters, I use C ++ and QImage from the Qt library.

I iterate through the directory and using the QImage constructor on the image path. This, of course, is rather slow and makes the application unacceptable. However, this allows me to detect invalid image files and ignore them early on.

, , , .

. .. , , .

,

, ? -, , ? , .

, , / . , ? .

+2
5

Unix file ( ) . , ( ).

( ), , ( man magic). /usr/share/file/magic ( Ubuntu). , PNG :

0       string          \x89PNG\x0d\x0a\x1a\x0a         PNG image
!:mime  image/png
>16     belong          x               \b, %ld x
>20     belong          x               %ld,
>24     byte            x               %d-bit
>25     byte            0               grayscale,
>25     byte            2               \b/color RGB,
>25     byte            3               colormap,
>25     byte            4               gray+alpha,
>25     byte            6               \b/color RGBA,
>28     byte            0               non-interlaced
>28     byte            1               interlaced

"" file (, -, BSD).

+4

2 : QImageReader .

, .format .

Qt (http://qt-project.org/doc/qt-4.8/qimagereader.html#format):

, QImageReader . . : QImageReader reader ( "image.png" ); //reader.format() == "png" - (, ), , QByteArray().

+3

, , , , . Qt:: Concurrent , , . , , , - .

0

, , , , , . , , ram, , ? IE: - 1 2 . , , , .

0

, , () . , , , .

, . , , , .

The Old New Thing.

0

Source: https://habr.com/ru/post/1534339/


All Articles