wget 您所在的位置:网站首页 newimage/wlast1.gif wget

wget

2022-03-26 22:20| 来源: 网络整理| 查看: 265

You can use curl to download parts of the image. It all depends on how robust it has to be. A test-case could be first 500 bytes. Seems to work for a lot of png and jpg, then use identifyor the like to check the size.

curl -o 500-peek -r0-500 "http://example.net/some-image.png"

Edit:

Long time since I wrote image parsers, but gave it some thought and refreshed some of my memory.

I suspect that it is all kind of images you want to check (but then again, perhaps not). I'll describe some of the more common ones: PNG, JPEG (JFIF) and GIF.

PNG:

These are simple when it comes to extraction of size. A png header stores the size within the first 24 bytes. First comes a fixed header:

byte value description 0 0x89 Bit-check. 0x89 has bit 7 set. 1-3 PNG The letters P,N and G 4-5 \r\n Newline check. 6 ^z MS-DOS won't print data beyond this using `print` 7 \n *nix newline.

Next comes chunks trough out the file. They consist of a fixed field of length, type and checksum. In addition an optional data section of length size.

Luckily the first chunk is always an IHDR with this layout:

byte description 0-3 Image Width 4-7 Image Height 8 Bits per sample or per palette index ... ...

By this we have that sizes are byte 16-20, and 21-24. You can dump the data by e.g. hexdump:

hexdump -vn29 -e '"Bit-test: " /1 "%02x" "\n" "Magic : " 3/1 "%_c" "\n" "DOS-EOL : " 2/1 "%02x" "\n" "DOS-EOF : " /1 "%02x" "\n" "NIX-EOL : " /1 "%02x" "\n" "Chunk Size: " 4/1 "%02u" "\n" "Chunk-type: " 4/1 "%_c" "\n" "Img-Width : " 4/1 "%02x" "\n" "Img-Height: " 4/1 "%02x" "\n" /1 "Depth : %u bit" "\n" /1 "Color : %u" "\n" /1 "Compr.: %u" "\n" /1 "Filter: %u" "\n" /1 "Interl: %u" "\n"' sample.png

On a Big Endian/Motorola machine one could also print the sizes directly by:

hexdump -s16 -n8 -e '1/4 "%u" "\n"' sample.png

However, on Little Endian / Intel, it is not that easy, and it is nor very portable.

By this it is we could implement a bash + hexdump script as in:

png_hex='16/1 "%02x" " " 4/1 "%02x" " " 4/1 "%02x" "\n"' png_valid="89504e470d0a1a0a0000000d49484452" function png_wh() { read -r chunk1 img_w img_h


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有