Jump to content

Different Image Size


j.silver

Recommended Posts

Hi all,

 

I have uploaded an image to a folder/directory and stored its size using the $_FILES['image']['size'] superglobal. While the image source size was reading 153kb, the stored size is 157317. Why there is a difference in size?

Link to comment
Share on other sites

A kilobyte is 2^10 bytes.

 

2^10 * 153 = 156672.

If you account for the fact that the number is rounded down the file should be the exact same size.

 

We can do it the other way around, divide bytes by 2^10 and truncate the result:

157317 / 2^10 = 153.629882813

Truncating (removing the decimal part) results in 153.

 

A megabyte is 2^20 bytes and gigabyte is 2^30 bytes.

Link to comment
Share on other sites

Note that hardware manufacturers like to use the definition that 1KB = 1000 bytes, instead of 1024 (2^10). That's why you can buy a hard drive which says it is 1TB, but when you install it then Windows claims it is 909GB. That's because to a hardware manufacturer, 1TB = 1 trillion bytes, but to software programmers 1TB = 2^40 = 1099511627776 bytes.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...