Board index » delphi » reduce jpeg size

reduce jpeg size


2007-11-16 04:43:33 AM
delphi188
I need to copy jpegs from a folder into a Mysql blob field. I want to
restrict the jpeg file size to say 1/2 meg. Is there a component to do this
out there.
Cheers
SteveW
 
 

Re:reduce jpeg size

SteveW writes:
Quote
I need to copy jpegs from a folder into a Mysql blob field. I want to
restrict the jpeg file size to say 1/2 meg. Is there a component to
do this out there.

Cheers

SteveW
Not seriously, but:
quality := 95;
repeat
SaveJpeg (jpeg-file);
Dec (quality, 5);
until FileSize (jpeg-file) < 500000;
or something more efficient along those lines.....
David
 

Re:reduce jpeg size

You can restrict the size either by:
- Reducing the image size (e.g. going from 800x600 to 400x300 will make it 4
times as small)
- Reduce the quality.
- Sometimes you can already compress a jpeg simply by recoding it with
optimized huffman tables (this is lossless).
I wouldn't touch the quality factor too much, because at very low qualities,
the image will look awful, it will actually look a lot better when resized.
A quality of about 70 is about the minimum I would recommend.
The standard Jpeg unit in Delphi can save with reduced quality, and you can
create a reduced size image with the Canvas.StretchDraw command, or on
low-level with the StretchBlt command (WinGDI).
The delphi Jpeg unit is a wrapper for C code. If you want a Jpeg lib with
Delphi source code, have a look at our new NativeJpg library:
www.simdesign.nl/nativejpg.html
Nils Haeck
www.simdesign.nl
"SteveW" <XXXX@XXXXX.COM>schreef in bericht
Quote
I need to copy jpegs from a folder into a Mysql blob field. I want to
restrict the jpeg file size to say 1/2 meg. Is there a component to do this
out there.

Cheers

SteveW

 

Re:reduce jpeg size

Nils Haeck writes:
[]
Quote
I wouldn't touch the quality factor too much, because at very low
qualities, the image will look awful, it will actually look a lot
better when resized. A quality of about 70 is about the minimum I'd
recommend.
[]
Nils Haeck
www.simdesign.nl
Agreed on the minimum - my pseudo-code should have shown that limit. For
resizing, I'd recommend full interpolation rather than the Stretch
commands - at least if quality matters. If you /must/ stretch, make it an
exact multiple of two (i.e. 2000 x 1500 =>1000 x 750 etc.)
Cheers,
David
 

Re:reduce jpeg size

Quote
Agreed on the minimum - my pseudo-code should have shown that limit. For
resizing, I'd recommend full interpolation rather than the Stretch
commands - at least if quality matters. If you /must/ stretch, make it an
exact multiple of two (i.e. 2000 x 1500 =>1000 x 750 etc.)
Agreed :) Of course the StretchDraw is bad-quality but the only thing
available with just Delphi. I'd advise Graphics32 for that.
Nils