Convert IMG to IMG.GZ Online (Adding Gzip's RFC 1952 Compression)
What actually happens when an uncompressed img container gets wrapped in gzip's formally specified compression layer for the first time.
- Add a file Choose or drop it here
- Pick the format Change it whenever needed
- Download the result After conversion completes
IMG-TO-TAR.GZ — Adding Gzip's RFC 1952 Wrapper to an Uncompressed IMG
A plain .img file bundles files using 512-byte header blocks, a structure standardized as USIMG in POSIX.1-1988, but has no compression built into it at all — a folder of files wrapped in a .img comes out close to the same total size as the originals, plus a small amount of header overhead. Converting that IMG into a IMG.GZ means wrapping the entire img stream in gzip, whose container structure is precisely defined in RFC 1952, a separate specification from DEFLATE, the actual compression algorithm gzip uses underneath, which has its own specification in RFC 1951.
RFC 1952's header begins with two fixed identification bytes (0x1F and 0x8B), followed by a compression-method byte and a flags byte controlling which optional fields appear, such as the original filename or a comment. None of that outer gzip structure touches or reinterprets anything inside the img stream it wraps — the 512-byte img headers underneath remain exactly as they were, just compressed rather than stored directly.
That separation between the two layers is precisely why the conversion never has to inspect what's inside the img archive at all. Gzip doesn't know or care whether the stream it's compressing contains one file or thousands, what their permissions are, or how deeply nested their paths are — it simply reads bytes in, applies DEFLATE, and writes compressed bytes out, leaving every detail of img's own internal structure to be reconstructed later, once the gzip layer comes back off during extraction.
IMG-TO-TAR.GZ — Why Gzip Compresses an Existing IMG Stream Differently Than Bzip2 Would
DEFLATE, the algorithm inside gzip, uses a 32 KB sliding window and looks for repeated byte sequences within that limited span, combined with Huffman coding on the result. Applied to a img stream specifically, this means DEFLATE can only find and exploit repetition between bytes that are close together in the stream — a repeated filename or permission pattern in a header, for instance, compresses well only if it recurs within roughly 32 KB of its previous occurrence, a real, concrete limitation compared to the much wider spans other compressors can reference.
What DEFLATE trades away in reach, it gains back in speed: its simpler pattern-matching approach runs considerably faster in both directions than the Burrows-Wheeler transform bzip2 would apply to the same img stream, which is the core, well-documented reason gzip remains the default choice in many pipelines even where it doesn't produce the smallest possible result. At the very end of the gzip stream, an ISIZE field records the original uncompressed size — but that field is only 32 bits wide, storing the size modulo 2^32 per RFC 1952, meaning any img stream 4 GB or larger produces a wrapped-around, inaccurate reported size in that trailer even though the img data itself extracts perfectly correctly.
IMG-TO-TAR.GZ — What Compressing a IMG Into IMG.GZ Gains and Costs
- Gain — real size reduction with fast turnaround: text-based content shrinks meaningfully, and DEFLATE's speed means the compression step itself adds relatively little time compared to heavier algorithms.
- Gain — a formally specified container: RFC 1952 defines gzip's header and trailer precisely, so any RFC-compliant gzip reader can decompress the result predictably.
- Gain — parallel compression through pigz: a multithreaded gzip reimplementation can spread the work of compressing a large img stream across multiple CPU cores, producing standard gzip output any ordinary tool reads normally.
- Lose — accurate size reporting past 4 GB: the ISIZE trailer's 32-bit width cannot represent the true uncompressed size of a very large img stream without wraparound.
- Lose — some compression ratio versus wider-window alternatives: bzip2's larger blocks and xz's much bigger dictionary both commonly out-compress gzip's fixed 32 KB window on repetitive, text-heavy img contents.
- Lose — near-zero shrinkage on already-compressed content: if the original IMG mostly held JPEG, MP4, or MP3 files, DEFLATE finds little repetition left to exploit, the same limitation shared by essentially every general-purpose compressor.
IMG-TO-TAR.GZ — Software That Turns a Plain IMG Into Gzip-Compressed Output
GNU img performs this exact conversion directly with its -z flag (or --gzip), reading an existing img stream and piping it through gzip in a single command; BSD img, the default on macOS, supports the same flag. Both ship by default on essentially every Linux distribution and on macOS, meaning this specific conversion requires no additional installation on either platform.
Windows has included img.exe, based on libarchive's bsdimg, since Windows 10 build 1803, capable of the same gzip compression from the command line, and Windows 11's 24H2 update added native File Explorer support for opening .img.gz archives directly, built on that same open-source libarchive project — support that simply didn't exist a few years earlier, when this conversion on Windows meant installing 7-Zip or a similar third-party tool specifically.
Pigz, the parallel gzip implementation written by Mark Adler (one of gzip's own original authors), divides input into 128 KB chunks and compresses them across multiple CPU cores at once; documented benchmarks show a multi-gigabyte img stream compressing in a small fraction of the time single-threaded gzip needs on the same multi-core hardware, though pigz's own documentation notes decompression isn't parallelized nearly as much, since DEFLATE decoding is inherently more sequential than encoding.
On the graphical side, 7-Zip and PeaZip on Windows both accept an existing .img file as input and can apply gzip compression to it directly. 7-Zip's own creation dialog treats this as a distinct step over an already-built img archive rather than a single combined "img.gz" option in its main archive-type list, which mirrors the same two-stage reality that GNU img's -z flag simply automates behind one command.
IMG-TO-TAR.GZ — Real Problems Reported When Adding Gzip Compression to a IMG
A documented issue reported on several bug trackers involves a tool displaying an obviously wrong, sometimes negative, uncompressed size for a newly compressed IMG.GZ built from a very large original img stream — tracing directly back to ISIZE's 32-bit width, and in some implementations, to that value being read as signed rather than unsigned. The reliable fix reported in these threads is decompressing the file and counting bytes directly rather than trusting any tool's reported size for img streams anywhere near or beyond 4 GB.
A second recurring pattern involves someone compressing a folder that mixes source code with large media files into one IMG.GZ, expecting the combined result to shrink close to what the text portion alone would achieve, then being surprised when the overall reduction is much smaller — the media files dominate the total size and barely compress at all, dragging down the average regardless of how well the text-based portion compressed on its own.
A third documented complaint involves expecting pigz to meaningfully speed up decompressing an existing IMG.GZ the same way it speeds up creating one, then finding decompression times barely change — pigz's own documentation addresses this directly, since a single DEFLATE stream's decoding is a more inherently sequential process than encoding is, limiting how much decompression parallelism is actually possible.
IMG-TO-TAR.GZ — Plain IMG Compared With Its Gzip-Compressed Counterpart
| Feature | Plain IMG | IMG.GZ |
|---|---|---|
| Compression | None | Gzip (DEFLATE), RFC 1951/1952 |
| Compression speed | N/A | Fast, 32 KB sliding window |
| Typical size vs. original | ~100% (plus small header overhead) | Smaller on text; minimal gain on media |
| Uncompressed-size field limit | N/A | 32-bit, wraps past 4 GB |
| Parallel compression tool | N/A | pigz (chunk-independent) |
| Windows GUI support | Native since Windows 11 24H2 | Native since Windows 11 24H2 |
IMG-TO-TAR.GZ — Questions About Compressing a IMG Archive With Gzip
Will converting my IMG to IMG.GZ always shrink it noticeably?
Usually, since the original IMG had zero compression, but the actual reduction depends on content — text and source code shrink meaningfully, while already-compressed media like JPEG or MP4 files shrink very little.
Does adding gzip compression change the files themselves?
No. Gzip compresses the img stream as a whole; the individual files come out byte-for-byte identical once the archive is decompressed and extracted.
Why does my file manager show an odd uncompressed size for a large IMG.GZ?
Gzip's ISIZE trailer field is only 32 bits wide and stores the original size modulo 2^32 per RFC 1952 — a documented format limitation for anything 4 GB or larger, not a bug in a specific tool.
Is gzip or bzip2 the better choice for compressing a plain IMG?
It depends on priorities: gzip compresses and decompresses considerably faster, while bzip2 often produces a smaller file on text-heavy content thanks to its wider block size.
Do I need extra software to compress a IMG into IMG.GZ?
Not on Linux or macOS, where GNU img and BSD img both support gzip compression directly via the -z flag. On Windows, img.exe (build 1803 and later) supports the same flag from the command line, and no separate installation is required.