JamesWilson
JamesWilson

Reputation: 4840

Calculate image height using file size and width

I'm not very hopeful that this is actually even possible because JPG is a lossy compression format, but I'll ask anyway.

I have some incomplete metadata about an image, and need to figure out the dimensions without loading the file into memory, or using command-line tools like imagemagick.

This is what I know:

Assuming the height could be variable, is there a mathematical equation I can use to calculate the height predictably?

Upvotes: 1

Views: 371

Answers (1)

user1196549
user1196549

Reputation:

No, there is no relation between the number of pixels and the compressed size.

You can try your luck by analyzing the file header to get the width/height tags. A library like jpeglib allows you to read just the header, but it takes some effort to integrate it.

Upvotes: 4

Related Questions