Skip to content
JPG실무 경험

How I Fixed a .jpg Image That Would Not Open on Windows

2 min readWorkMoved from my Tistory blogRead the Korean original

Error screen: "The photo cannot be opened because it is either in an unsupported format or corrupted."
Figure 1. Error screen: "The photo cannot be opened because it is either in an unsupported format or corrupted."

Here is how I fixed images with a .jpg extension that downloaded on Windows but would not open.
The problem happened because a screenshot taken on an Android phone was saved with a .jpg extension, while its actual internal format was AVIF.

❗️ The problem

The image opened normally on a Mac or in the Chrome browser, but it could not be opened in certain Windows environments.

🔍 Analysis

I checked the problem image in the terminal.

Inspecting the image files in the terminal
Figure 2. Inspecting the image files in the terminal
text
autowini2@autowiniui-MacBookPro-5 Desktop % file test.jpg
test.jpg: ISO Media, AVIF Image

autowini2@autowiniui-MacBookPro-5 Desktop % file umsungjun.jpg
umsungjun.jpg: JPEG image data, JFIF standard 1.01, resolution (DPCM), density 37x37, segment length 16, baseline, precision 8, 500x500, components 1
  • test.jpg → the extension is .jpg, but the actual internal format is AVIF
  • umsungjun.jpg → a normal JPEG

Cause

When you take a screenshot on Android, it is saved in AVIF (or HEIF) format, depending on the device's default settings. But some environments force a .jpg extension onto the file, so the actual format and the extension no longer match.

  • AVIF: A newer image format with high compression efficiency and a small file size for its quality. Supported by default in recent Android versions.
  • JPEG: A format that has been the standard for a long time. Compatible with most operating systems and apps.
  • Windows default Photos app: Does not support AVIF → the extension is .jpg but the file is actually AVIF, so you get a corrupted file error.

What is a format?

A format is the specification (file type) that defines how image data is compressed and stored.

  • JPEG → lossy compression, high compatibility
  • PNG → lossless compression, supports transparent backgrounds
  • AVIF → newer specification, high compression efficiency

In other words, the .jpg extension is only a shell. Whether the file opens depends on the format of the actual data stored inside it.

✅ The fix

As with the Android screenshot, when the extension is .jpg but the internal format is AVIF, the file would not open in the default Windows viewer.
To fix this, I made the download convert the image to JPG through a Canvas before saving it, if the blob's MIME type is image/avif.

ts
/**
 * @description File download function
 * @param url - File URL
 * @param filename - Name of the file to download
 */
export const fileDownload = async (url: string, filename: string) => {
  const res = await fetch(url);
  if (!res.ok) throw new Error('파일 다운로드에 실패했습니다.');

  const blob = await res.blob();

  // Convert avif → jpg (only when the internal MIME type is avif)
  const convertIfAvif = async (blob: Blob): Promise<Blob> => {
    if (blob.type === 'image/avif') {
      const img = await createImageBitmap(blob);
      const canvas = document.createElement('canvas');
      canvas.width = img.width;
      canvas.height = img.height;
      const ctx = canvas.getContext('2d');
      if (!ctx) throw new Error('Canvas context 생성 실패');

      ctx.drawImage(img, 0, 0);
      return new Promise<Blob>((resolve, reject) => {
        canvas.toBlob(
          (newBlob) => {
            if (newBlob) resolve(newBlob);
            else reject(new Error('JPG 변환 실패'));
          },
          'image/jpeg',
          0.9
        );
      });
    }
    return blob;
  };

  const finalBlob = await convertIfAvif(blob);

  const objectUrl = URL.createObjectURL(finalBlob);
  const link = document.createElement('a');

  // If the internal format was avif, force the extension to jpg
  const finalFilename =
    blob.type === 'image/avif'
      ? filename.replace(/\.[^/.]+$/, '') + '.jpg'
      : filename;

  link.href = objectUrl;
  link.download = finalFilename || `file-${Date.now()}`;
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);

  // Free the memory
  setTimeout(() => URL.revokeObjectURL(objectUrl), 100);
};

💡 What I learned

At first I only thought, “The file seems to be corrupted.” This experience taught me that a file's extension and its actual format can be different.

If a similar problem comes up again, I think I'll be able to find the cause and fix it faster.

  • #AVIF
  • #JPG
  • #The photo cannot be opened because it is either in an unsupported format or corrupted.
  • #Windows
  • #bug fix
  • #Android
  • #image format

More in Work