I need to find size of a .jpg
file without its header (or metadata). How can I do that?
I guess JPEG data contains two parts:
Thanx for comments. As Anon Coward said I've found this useful image which shows different parts of a JPEG file:
I wanted length of Image Data
so I need to find 0xFF 0xDA
and count bytes from there, then subtract 16 from it. Here is the code:
def get_JPEG_size(file_path):
total_size = os.path.getsize(file_path)
with open(file_path, 'rb') as f:
s = f.read()
header_size = s.find(b'\xff\xda')
if header_size == -1:
print("`FF DA` not found!")
return 0
header_size += (2 + 12) + 2
data_size = total_size - header_size
return data_size