Solved

How to reduce the size of a JPG?

Posted on 2000-03-19
11
849 Views
Last Modified: 2008-02-01
I have a JPG file which is say 15KB in size, I need to open and display the file, apply an effect say gamma reduction( not necessary this effect, as what I want is just to reduce the quoality of the JPG so that the size can be reduced ) and save the file so that the size will be smaller say 10KB.

Is there any Delphi component which can help me do that or someone have codes for that?
0
Comment
Question by:foxvision
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 1

Expert Comment

by:X_Kalibur
ID: 2634498
foxvision,

its an interesting problem....considering that a JPEG file is compressed quite a bit (depending on the level of compression)...

i think what you'd need to do it to open up the image, and then re-save the file with a higher compression setting..

i doubt that changing the gamma of an image will greatly reduce the file size..

hth,

-x
0
 

Author Comment

by:foxvision
ID: 2634530
X Kalibur,

Exactly how do you do that in Delphi? When a JPG file is saved using higher compression rate, will it look different?

Please advice. I wanted to do that because I want to reduce that size of a JPG files so that it can be downloaded/view from my web sites faster for other users. I know of many commercial software in the market which can produce exactly what I want but hey, I got Delphi here with me and I want to come out with my program. :)

Thanks.

0
 
LVL 1

Expert Comment

by:yk030299
ID: 2634622
I sugguested you that
using the Photoshop SDK, you can save it as file with lower color-depth or resolution.
E.g. HighColor->256Color.
To import Photoshop TypeLibrary:
....\Delphi4\bin\TlibImp ...\Photoshop 5.0\TypeLibrary.TLB
.....See also www.djpate.freeserve.co.uk/autoPShp.htm
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:rwilson032697
ID: 2634653
Or...

You could load the JPEG into a TJEPGImage component (comes with delphi) and adjust the CompressionQuality property downwards to reduce the size fo the file.

Cheers,

Raymond.
0
 

Author Comment

by:foxvision
ID: 2634660
yk,

Sorry I have to temporarily reject your answer as I have a few questions to it.

1st, when I import Photoshop SDK, does it mean I have to distribute the DLLs that come with it? What I'm looking for is native Delphi components because I have to see exactly how it is done so that I can code it.

2nd, the page you've provided: www.djpate.freeserve.co.uk/autoPShp.htm doesn't seem to be exist. Can you give me a good one? Post it as an answer if the link is OK so that I can accept your anser.

Thank you.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2634675
One thing you should note about JPEG is that it is oriented towards realworld images (ie: 24 bit color), and tends not to compress so well when used on 256 colour images - so reducing the color depth may not buy you anything...

Cheers,

Raymond.
0
 
LVL 1

Expert Comment

by:yk030299
ID: 2634684
Hi Foxvision,
1) since you want native Delphi components, pls accept rwilson's comment if you are using Delphi5,too.
That I provided is the method I used before(D5 is not released).
2)http://www.djpate.freeserve.co.uk/AutoPShp.htm is.
I just copied from the URL of WebBrowser.
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 200 total points
ID: 2634686
You can do it like this:

var
  Jpeg : TJPegImage;

begin
  JPeg := TJegImage.Create(Nil);
  JPeg.LoadfromFile('fred.jpg');
  Jpeg.CompressionQuality := 50; // 50%
  JPeg.SaveToFile('SmallFred.jpg');
end;

Cheers,

Raymond.

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2634691
Ooops - don't forget to free jpeg... after saving it to the file...

Cheers,

Raymond.
0
 

Author Comment

by:foxvision
ID: 2634757
Thanks.
0
 
LVL 1

Expert Comment

by:X_Kalibur
ID: 2635642
yah..

ray's answer is a lot better than having to supply bulky SDK overhead (if you ever wish to distribute the app)...

i had a small hunch that there was a method to change the compresion quality of the JPG in teh JEPG unit, but i wasnt too sure.

now i know better :)

-x
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question