Save picture size

One of my software create photo gallery and it allows to update existing gallery → If a picture has not be modified then I don’t create it again. Then if I add a photo to a gallery I do not need to re-upload all the photos on the server.

To check if a photo changed, I check its size (width x height) and its size in byte. But I have a problem with the size (in bytes).
Please run the attach project “TestPictureSave.xojo_binary_project”, run it and select a picture file (bigger than 800 x 600), click the save button. The first time you click it and it will create a reduce picture (800 x 600) and save it adding “_Resized” to he file name.
Without doing anything else (simply run on the Break), click this save button again.

The program will load in “ImgTampAv1” the reduced picture file you just saved (if you look at it in the Debugger there is no Graphics).
Then the program will create “ImgTampAv2” from “ImgTampAv1“ (this time there is Graphics).
Then the program will create “ImgTampAp” from “ImgOriginal“ (with Graphics too).

I put those picture in MemoryBlock and I don’t understand why “ImgTampAv2” and “ImgTampAp” are not identical in JPG and TIFF (they are in PNG and BMP). I know JPG loses quality but “ImgTampAv2” is exactly “ImgTampAp” I saved before.

Do I do something wrong or is it a normal way?

TestPictureSave.xojo_binary_project.zip (14.7 KB)

I’ve had a quick look using Intel macOS 12.7.6.

Both TIFF images were the same size for me (macOS Preview states that it was saved with no compression).

With JPEG they would not be the same. ImgTampAv1 is the scaled version on disk which means it has lossy compression already applied. When you convert ImgTampAv1 to JPEG it has more lossy compression applied.

If you have a file Image1.jpg and you open it and save it as Image2.jpg, then open Image2.jpg and save it as Image3.jpg, the three files will not be the same and the quality will steadily deteriorate the more times you do it.

2 Likes

Thank you Kevin and Tim, I was wrong as effectively one of the picture I compared was compressed 2 times in JPEG and the other one only one time.
I put my sample in case someone read this topic in the future and want to do some tests.

TestPictureSave.xojo_binary_project.zip (17.5 KB)