2

I want to generate images with fixed file size (not image size). I've tried some of the solutions here Batch "resize" JPEG images to a fixed file size, but files generated are fixed in size on disk instead of the file size in bytes.

For example, I want the image size to be 33KB in bytes but actually it ends up 33KB on disk.

Kind: JPEG image
Size: 32,222 bytes (33 KB on disk)

Any ideas? Thanks!

3
  • Why do you need image files with such a precision in file size where a 4KB difference is so relevant? What are you trying to accomplish? Dec 14, 2013 at 0:51
  • possible duplicate of Batch "resize" JPEG images to a fixed file size
    – Excellll
    Jun 18, 2015 at 14:45
  • @ethanjyx: This is an old post that just resurfaced because a possible duplicate question was suggested that links to more answers. Two questions. 1st, can you post a comment on the current status of the problem (did you find a solution & if so, what was it? are you still looking for an answer or has this been overtaken by events?)? 2nd, once questions are posted, they take on a life of their own as they help others with a similar problem. Can you clarify whether your goal was a precise file size or a maximum file size? Compression can be hard to predict so most options target a max size.
    – fixer1234
    Jun 19, 2015 at 12:51

1 Answer 1

2

The final size on disk will depend on the cluster / sector size of the underlining filesystem used by the storage device (actually, the partition) the file is in. It is rounded up to the upper nearest value multiple of the sector size of your storage (for NTFS it is 4KB by default, but can be higher / smaller).

Therefore, a single byte extra could mean a file taking up multiple kilbytes of your storage. In fact, that's the very cause for the problem of "slack space" on storage media, that is, the file wasted by unused space on the last sector of each file, a problem that is very noticieable when there are lots of really small files on a partition with a big sector size.

As to your question, there is no definite answer, and I believe it is a non-issue, unless you really need image files with such a precision in file size where a 4KB difference is significative.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .