Lymphatus / CaesiumPH

Lossless JPEG compression for photographers and webmasters
http://saerasoft.com/caesium/ph
GNU General Public License v3.0
90 stars 11 forks source link

Prevent bigger file sizes if original is smaller #4

Closed Voodoopupp closed 8 years ago

Voodoopupp commented 8 years ago

If you have a lot of really small images and try to save size, it can happen that casesiumPH is increasing the file size (e.g. 6000_4.jpg in the screenshot)

This should be prevented and instead it should a) copy the original to the folder or b) skip that image

I would prefer a) because afterwards it would be a mess to check always both folders.

The only concern is the compression setting in the preferences ("Keep exif", ...) - not sure, how to handle that.

bigger_size

Lymphatus commented 8 years ago

Definitely a), b) would be very confusing. Can you provide one or more of the images that actually have a size increase after compression? I'd like to have a look at them for testing purposes.

Voodoopupp commented 8 years ago

Can i just drop them here? Or will they get compressed or something by github? Or should I e-mail them?

Lymphatus commented 8 years ago

I think they won't be compressed by GitHub, but, just to be sure: caesiumph {at} saerasoft [dot] com

Voodoopupp commented 8 years ago

okay, email has been sent :)

Lymphatus commented 8 years ago

While I investigate on the compression results to completely avoid increasing the size - although it's impossible to be 100% sure it won't happen sometimes - there's the fix. Since we can't exactly predict the output filesize due to EXIF, the file is actually compressed and then the software will check whether the output is bigger or not. If this happens, the output file is removed and is replaced by a copy of it. More precisely, if we wanted to overwrite the originals, the output files are actually compressed in a temporary directory and eventually moved over the originals. The temporary folder is destroyed when CaesiumPH is closed.

Voodoopupp commented 8 years ago

Sounds great, so if we won´t overwrite the originals, let's say we sent the compressed images to a custom folder or subfolder it will

  1. compress images and send to the selected folder
  2. will now compare this folder with the temporary files?

Or will it be just on the fly image after image?

Lymphatus commented 8 years ago

On the fly. For each compressed file, it performs the check and copy the original file into the subfolder/custom folder.

This is the flow if we don't want to overwrite the originals:

  1. Compress the file into the new folder (or with a suffix)
  2. Compare sizes
  3. If the compressed is bigger, remove it and replace it with a copy of the original

Instead, if we want to overwrite them:

  1. Compress the file in a temporary folder (which is different everytime CaesiumPH is started)
  2. Compare sizes
  3. If the output is smaller, move the file from the temporary folder into the original one, overwriting the file (the original is actually being removed before moving the new one). If it's bigger, do nothing as the original is already in the right place
  4. Destroy the temporary folder on CaesiumPH exit

This way is a bit slower than the previous process because we need to remove/move some files in a few cases, especially when overwriting them. Also, doing this on the fly for each file ensures the right behaviour upon cancelling the process or if an unexpected error kicks in.

Voodoopupp commented 8 years ago

Okay, sounds exaclty the right way. Sure, speed is a bit slower, but I think in the end the result is the more important thing ;)