ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 resize images

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Kostas Posted - Jun 28 2025 : 05:38:07
I have several .png images with different file sizes.
Is there a way to automatically resize the images to a maximum size?

regards,
Kostas
3   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Jul 02 2025 : 21:49:40
Hi Kostas

There are multiple ways to reduce the file size of an image:

- Save to a more compressed format: If your images are PNG, then the easiest way to reduce file size is to save to lossy format like JPEG (if you don't need transparency) or WebP (if you need transparency)
- Improve compression: Many formats support compression options, including PNG, optimize these: http://www.imageen.com/help/TIOParams.html
- Resample the image to make it smaller (e.g. reducing the size of an image by 50% will make it around 75% smaller on disk)
- Reduce the colors: Generally not a recommended method


If you have a strict maximum size (e.g. due to database constraints) and you are using a format that supports compression (so cannot quickly calculate the final file size), then you will need to create a method that saves a temporary file (you should just save to a TMemoryStream for speed) and keeps optimizing the options above until it does not exceed the maximum size, e.g.

// Keep reducing the quality of the image until it matches our size constraint
jpegQ := 95;
sz := MaxInt;
While sz > Maximum_Size do
begin
  BMP.Params.JPEG_Quality := jpegQ;
  BMP.SaveToStream( ms, ioJPEG );
  sz := ms.Size;
  dec( jpegQ, 5 );
  if jpegQ < 10 ) then
    raise EException.create( 'cannot optimize this image enough' );
end;

// Do something with ms, e.g. output to file or database


Nigel
Xequte Software
www.imageen.com
Kostas Posted - Jul 02 2025 : 07:44:45
Hi Nigel,

sorry for the misunderstanding.
I don't want to reduce the image size in pixels, but rather the file size in KB.
All images should be a maximum of 400KB in size. I don't care about the resolution in pixels.

regards,
Kostas
xequte Posted - Jun 28 2025 : 20:50:27
Hi Kostas

You can resize images using the Resample() method:

http://www.imageen.com/help/TImageEnProc.Resample.html


Have you tried our batch processing demo?

\Demos\InputOutput\BatchConvert\BatchConvert.dpr

Nigel
Xequte Software
www.imageen.com