Save JPEG in fixed file size

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, xnview

Post Reply
User avatar
dominique
Posts: 72
Joined: Thu Nov 08, 2007 9:22 am

Save JPEG in fixed file size

Post by dominique » Fri Jul 25, 2008 1:57 pm

Hi xnview !
Do you have an option to adapt the JPEG quality automaticaly to obtain a required file size?
Or maybe do you know an algorithm able to do this with GFL functions?
Rgds
Dom

User avatar
xnview
Author of XnView
Posts: 32005
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Save JPEG fixin file size

Post by xnview » Fri Jul 25, 2008 1:58 pm

dominique wrote: Or maybe do you know an algorithm able to do this with GFL functions?
No, perhaps by adjusting quality and compress in memory
Pierre.

User avatar
dominique
Posts: 72
Joined: Thu Nov 08, 2007 9:22 am

Post by dominique » Fri Jul 25, 2008 2:04 pm

Ok I have this idea too... maybe I can do a dichotomy search with given bounds.
I'll give you some news when I have results.
Dom

vedavrata
Posts: 14
Joined: Wed Apr 07, 2010 6:44 am
Location: Odesa, Ukraine
Contact:

Save JPEG: how to see old/new file size, old/new visual qual

Post by vedavrata » Thu Apr 08, 2010 4:39 pm

When i save a JPEG file, i just can specify a "Quality" (%) but i can not see the old and the new file size, as well can not see the image difference (what i would lose), can't i ?..

How to see the both old (original) / new (will be saved) file size of JPEG file?
How to see the both old (original) image / new (will be saved) image simulaneously [in two modes "Fit to half a widnow / fit to half a widnow" and "No fit / no fit (i.e. 1:1 / 1:1)"] to evaluate visual quality ?

FYI: I use Linux (X11) version of XnView unber Ubuntu Linux.

User avatar
dominique
Posts: 72
Joined: Thu Nov 08, 2007 9:22 am

Re: Save JPEG in fixed file size

Post by dominique » Thu Apr 08, 2010 4:46 pm

You should post this the XnView section of the forum :D
Here is the GFLSDK forum.
Dom

vedavrata
Posts: 14
Joined: Wed Apr 07, 2010 6:44 am
Location: Odesa, Ukraine
Contact:

Re: Save JPEG in fixed file size

Post by vedavrata » Thu Apr 08, 2010 5:05 pm

dominique wrote:You should post this the XnView section of the forum :D
Here is the GFLSDK forum.
Excuse me.

User avatar
iycgtptyarvg
Posts: 81
Joined: Wed Jan 24, 2007 3:59 pm
Location: The Netherlands

Re: Save JPEG in fixed file size

Post by iycgtptyarvg » Tue Apr 20, 2010 3:00 pm

What I do is the following:

Set the initial quality to 90% and picture size to 100%

while(pic_size > wanted_size)
quality -= 5%
picture size -= 10%

So, the iterations go like this (quality, pic size):
1. 90%, 100%
2. 85%, 90%
3. 80%, 80%
4. 75%, 70%
5. 70%, 60%
...


Of course, if you only want to change the quality settings you can simply use the halving method which has complexity O(log n).

Example:
Org size 10MB, wanted size = 500KB
1. Q100% = 7MB (initial boundary)
2. Q10% = 20KB (initial boundary)
3. Q55% = 300KB (100+10 / 2)
4. Q78% = 650KB (100+55 / 2)
5. Q67% = 520KB (55+78 / 2)
6. Q61% = 460KB (55+67 / 2)
7. Q64% = 495KB (61+67 / 2)
8. Q65% = 510KB (64+67 / 2)

Result : Q = 64
(\__/)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.

Post Reply