?
Solved

How to reduce the size of a JPG?

Posted on 2000-03-19
11
Medium Priority
?
852 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 600 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

800 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