Danger: Your Image Files may be Destroyed by Default

Share

In image-editing, and when handling data in general, we say a program is destructive when it changes the original data permanently, and non-destructive when it leaves the original data untouched, and only modifies a copy of the data. In most cases, this isn't an issue, but when it comes to images, there are many programs that can destroy your images, your photos, your illustrations, without even telling you what they're doing. These are often image editors, but, surprisingly, even image VIEWERS can destroy your images. In this article we'll learn why and how.

The two important culprits are applications installed by default in Windows: the Microsoft Paint (an image editor) and the Microsoft Photos (an image viewer).

In Image Editors

The first problem occurs when opening an image in an image editor, editing it, and saving the edits overwrites the original image. This means if you open an image, crop it, and save it, for example, the image will become permanently cropped. You will never be able to crop another part of the image, because the data of the rest of the image will have been lost forever.

This happens if you open any image in Microsoft Paint and click File -> Save instead of File -> Save as.... The image file will be overwritten, and you'll lose the original image forever. If it's a PNG image, you may be able to recover it by clicking undo until all your edits are undone and then saving it again, but if what you opened was a JPG image, then opening it and saving it again, even if you don't edit anything in it, will create JPG artifacts due to the lossy nature of the JPG compression algorithm.

Complex image editors like Photoshop, GIMP, and Krita have their own image file format (.psd, .xcf, and .kra extensions respectively) that can save layer data and other settings specific of the program that can't be saved into common image formats like JPG (commonly used to store photos) or PNG (for transparency graphics). Consequently, if you edit an image in one of these, and try to save it, they'll typically save as a new file in their own format instead of overwriting the file you opened to edit. One exception occurs when you open an image and don't add any extra layers, then the program may overwrite the original JPG or PNG file.

In Image Viewers

A more surprising situation occurs with image viewers. Some image viewers provide the ability to rotate the image by 90 degrees. Normally you would think this is a non-destructive operation, after all, all you need to do is take the original image data and just render it rotated. But image viewers do something completely different and unexpected: they change the image file when you rotate the image in the viewer! More specifically, the JPG file format includes a header that describes the orientation of the JPG image, which describes whether or not the image is rotated by 90, 180, or 270 degrees. If you change this header, then a program that supports this header will display the image rotated according to the value in the header. There's a few interesting things about it.

First, changing the orientation header doesn't change the actual pixel data of the JPG image. This means the JPG file isn't uncompressed into pixels and then compressed again using the JPG codec—the image viewer saves the same compressed data it opened, except with a different header, which means JPG artifacts aren't generated by just changing the orientation. If you rotate the image by 90 degrees 4 times, you rotate it by 360 degrees and you should end up with the exact same file that you started with. If you did this in an image editor, you would end up with a slightly different file due to JPG artifacts, but because the image viewer doesn't recompress the data, this issue doesn't occur.

Second, not all programs actually support this JPG orientation header. If you noticed your JPG image is rotated in one program but in another program it's not, that because the JPG file contains an orientation header and one of the programs doesn't support it.

Third, the reason this orientation header exists to begin with is so that you can take a photo sideways and correct it to the proper orientation without destructively recompressing the JPG data. So this is actually a feature for non-destructive editing, as it doesn't destroy the pixel data, but it's still kind of destructive as it changes the header part of the JPG file.

This feature is mainly found in image viewers that are designed to view photos taken from cameras, which is the typical use case for an image viewer. If there was an image viewer designed to view images you downloaded from the Internet—such as wallpapers—it probably wouldn't change the orientation header just to display the image rotated on screen. For example, personally I use JPEGView on Windows, which can rotate and flip images, but doesn't change the orientation header in the JPG files (which is rather ironic considering its name).

Video

Comments

Leave a Reply

Leave your thoughts! Required fields are marked *