Solved

How to reduce the size of a JPG?

Posted on 2000-03-19
11
831 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Ooops - don't forget to free jpeg... after saving it to the file...

Cheers,

Raymond.
0
 

Author Comment

by:foxvision
Comment Utility
Thanks.
0
 
LVL 1

Expert Comment

by:X_Kalibur
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Firewall issues 6 84
Delphi cmd execution 6 40
Intraweb download file link ? 1 88
Run video youtube webbrowse 10 44
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now