Solved

How to reduce the size of a JPG?

Posted on 2000-03-19
11
833 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Internet Explorer View Settings Question 15 111
FMX enumerated colours 2 100
firemonkey keyboard covers the controls 1 26
scroll down TListBox component in Delphi 1 11
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

777 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