1

I checked the http header and their content type is both image/png. I need to sth different based on if an image is a PNG or APNG, like if it's a PNG, display it directly. If it's an APNG, display the first frame and only start downloading the whole image when the user taps the image.

njuxjy
  • 415
  • 4
  • 13

2 Answers2

5

The mime type of APNG is image/apng: https://wiki.mozilla.org/APNG_Specification.
If the content type in the HTTP Header is wrong, there is no way to identify an APNG without start the download.
But you can try to download only the first bytes/kilobytes to check the type, according to specification : "To be recognized as APNG an 'acTL' chunk must appear in the stream before any 'IDAT' chunks"

Stefano Balzarotti
  • 1,760
  • 1
  • 18
  • 35
  • 3
    Good answer, but to locate the IDAT chunks one needs quite a bit more than "the first bytes". gAMA and iCCP chunks, for example, can easily span several kilobytes. Also, this would require actual *parsing* of the chunks while the image is loading. – Jongware Nov 16 '16 at 11:05
  • 1
    The registered IANA MIME type for apng is image/vnd.mozilla.apng (see http://www.iana.org/assignments/media-types/image/vnd.mozilla.apng). The APNG spec claims image/apng but that was never registered. – Glenn Randers-Pehrson Dec 14 '16 at 19:18
  • @Glenn Randers-Pehrson true but Mozzilla official specification suggest to use "image/apng" https://wiki.mozilla.org/APNG_Specification#MIME_type **APNG can be identified using the image/apng MIME type.** in MIME_type section of specification. Here there is a discussion about the correct mime type to use: https://bugzilla.mozilla.org/show_bug.cgi?id=1160200#c37 – Stefano Balzarotti Dec 14 '16 at 21:38
-3

Once you detect it, then what? It seems you assuming you can stop the browser from downloading the whole file. I don't think that's possible.

maxst
  • 226
  • 1
  • 1
  • 1
    This is not an answer, please use comments for ask clarifications. Also, who tell you that the image will be downloaded from a browser? The question is related to iOS. – Stefano Balzarotti Nov 16 '16 at 16:48