Solved

How to reduce the size of a JPG?

Posted on 2000-03-19
11
835 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
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

861 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