Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6006141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:29:50+00:00 2026-05-23T01:29:50+00:00

How can I calculate file size of resized image (for example JPEG) before I

  • 0

How can I calculate file size of resized image (for example JPEG) before I resize it?

I need to send HTTP request Content-length, then I will resize image, else nginx get me time out response.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:29:51+00:00Added an answer on May 23, 2026 at 1:29 am

    zen0n, if you absolutely have to do this, using Andrew’s suggestion with a minor modification is the only way to do it (do the entire resize operation, outputting the bytes to a ByteArrayOutputStream so you can count them before hand).

    The modification I would use is doing this server-side with a simple image-resizing library like imgscalr, pass in the BufferedImage that represents the loaded image, and get back a resized BufferedImage that represents the new-sized image. Then pump it through ImageIO.write and output it to a BufferedArrayOutputStream.

    Then set your “Content-Length” header and stream the image contents back.

    Because converting raw image bytes to a JPG introduces a compression and encoding sequence of events, there is no accurate way to pre-predict the exact file length before hand and then use ImageIO.write to stream the bytes back to the client. You’ll have to resize the image completely first (in memory) using the technique mentioned above, THEN write the data back to the client.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the need to calculate the size of a file I am encrypting
I can calculate the size of the files in a tarfile in this way:
Can someone explain with an example how we can calculate the time and space
How can I calculate the number of differences between two NSStrings. Example: NSString 1
How can i calculate the size of only some rows for each table? For
I read the manual that filesize() is able to calculate file size from remote
I need to calculate the percentage of a file uploaded to the server. I
Ho do i calculate the size of a AES256 encrypted file/buffer. I do malloc
I need a copy-free re-size of a very large mmap file while still allowing
Hi i was wondering if anyone knows how i can calculate the difference between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.