Why I get the error: "Not a JPEG file: starts at 0x89 0x50"

Why do I get the message "Not a JPEG file: starts with 0x89 0x50" when I try to open a jpg file?

+66
image png jpeg corruption
Jul 03 '12 at 11:45
source share
7 answers

The file is actually PNG with the wrong file extension. "0x89 0x50" is the launch of a PNG file.

+74
Jul 03 '12 at 11:45
source share

Your file is not a JPEG file, it is simply renamed from PNG to JPEG somewhere along the way. Some programs will open this as a recognized file extension and infer the type from the prefix, but obviously not the one you are using.

+54
Jul 03 2018-12-12T00:
source share

just rename * .jpg to * .png. Or open this file in a browser

+3
Nov 27 '17 at 16:09 on
source share

Here is a quick step to verify the real file type on a Unix-like platform:

using the file command, for example:

file e3f8794a5c226d4.jpg 

and conclusion

 e3f8794a5c226d4.jpg: PNG image data, 3768 x 2640, 8-bit/color RGBA, non-interlaced 

which prints information about the file, and can also check if the specified file was destroyed.

+3
Nov 27 '18 at 5:03
source share

This is the error response when trying to open a PNG file using the JPEG file viewer that libjpeg uses to open jpeg files. Your file has been renamed from png to JPEG, as indicated in earlier answers.

+1
May 17 '16 at 13:34
source share

Here is a python script to identify these jpg error images in a directory.

 import glob import os import re import logging import traceback filelist=glob.glob("/path/to/*.jpg") for file_obj in filelist: try: jpg_str=os.popen("file \""+str(file_obj)+"\"").read() if (re.search('PNG image data', jpg_str, re.IGNORECASE)) or (re.search('Png patch', jpg_str, re.IGNORECASE)): print("Deleting jpg as it contains png encoding - "+str(file_obj)) os.system("rm \""+str(file_obj)+"\"") except Exception as e: logging.error(traceback.format_exc()) print("Cleaning jps done") 
+1
Oct 23 '17 at 8:58
source share

Here's a modified version of the Mohit script. Instead of deleting files with the wrong name, it non-destructively renames them.

It also replaces os.system () calls with subprocess calls, which solves problems with quotes in file names.

 import glob import subprocess import os import re import logging import traceback filelist=glob.glob("/path/to/*.jpg") for file_obj in filelist: try: jpg_str = subprocess.check_output(['file', file_obj]).decode() if (re.search('PNG image data', jpg_str, re.IGNORECASE)) or (re.search('Png patch', jpg_str, re.IGNORECASE)): old_path = os.path.splitext(file_obj) if not os.path.isfile(old_path[0]+'.png'): new_file = old_path[0]+'.png' elif not os.path.isfile(file_obj+'.png'): new_file = file_obj+'.png' else: print("Found PNG hiding as JPEG but couldn't rename:", file_obj) continue print("Found PNG hiding as JPEG, renaming:", file_obj, '->', new_file) subprocess.run(['mv', file_obj, new_file]) except Exception as e: logging.error(traceback.format_exc()) print("Cleaning JPEGs done") 
+1
Apr 15 '18 at 23:19
source share



All Articles