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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Add barnding watermark on pictures in a folder
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

esprd

14 Posts

Posted - Nov 12 2025 :  03:05:27  Show Profile  Reply
Hi,

I need to create a tool which will add branding of all JPG present in a folder (picture or text).

I know how to do it, but I find it quite long (~ 3 s / picture, 1 min for 19 pictures), knowing that I have hundreds of pictures to process.

Below is my code, using layers. I already fill the branding layer once. But what costs is the load of the background (6960x4640) and the LayersSaveMergedTo process


procedure TForm4.btnWatermarkProcessClick(Sender: TObject);
var
  MyImageEn : TImageEnView ;
  FolderName, NewFolderName, PictName : string ;
  FileList : TStringDynArray ;
  i : integer ;
  Cnt1, Cnt2 : integer ;

begin
  //---- For all "_VIS.JPG" files in background image folder, add a watermark and save to _Watermarked sub folder
  // Get folder name
  FolderName := ExtractFilePath( OpenPictureDialog1.FileName ) ;

  // Create _Watermarked sub folder
  NewFolderName := FolderName + '_Watermarked\' ;
  if not DirectoryExists( NewFolderName ) then
    ForceDirectories( NewFolderName ) ;

  // Get FileList
  FileList := TDirectory.GetFiles( FolderName, '*_VIS.JPG' ) ;

  MyImageEn := TImageEnView.Create( nil ) ;
  MyImageEn.IO.LoadFromFile( OpenPictureDialog1.FileName ) ;

  // picture layers
  if MyImageEn.LayersCount <> 2 then
  begin
    MyImageEn.LayersClear( false );
    MyImageEn.LayersAdd(MyImageEn.Layers[0].Kind,
                           MyImageEn.Layers[0].PosX,
                           MyImageEn.Layers[0].PosY,
                           MyImageEn.Layers[0].Width,
                           MyImageEn.Layers[0].Height) ; // Append a new layer
  end ;

  MyImageEn.LayersCurrent := 1 ;
  MyImageEn.IO.LoadFromFile( 'C:\_DEV\MyBranding.png' ) ;

  // Set background as current layer
  MyImageEn.LayersCurrent := 0 ;

  // Process on folder files
  for i := 0 to High( FileList ) do
  begin
    // Load picture as background
    MyImageEn.IO.LoadFromFile( FileList[i] ) ;

    // New pict name
    PictName := StringReplace( FileList[i], FolderName, NewFolderName, [rfReplaceAll] ) ;

    // Save picture
    if FileExists( PictName ) then
      System.SysUtils.DeleteFile( PictName ) ;

    MyImageEn.LayersSaveMergedTo( PictName );
  end;

  MyImageEn.Free() ;

end;



Is there another faster way to do that ? Could I do the same without really loading the pictures ? I've made some tests on web sites dedicated to watermarking and it was much more faster.

Regards



ep

xequte

39245 Posts

Posted - Nov 12 2025 :  13:19:14  Show Profile  Reply
Hi

I expect most of the slowness will simply be the I/O (loading and saving) of each image, so your first check should be that you are using the best imaging engine. You will find DLL or WIC to be faster than native for JPEG:

http://www.imageen.com/help/TIEGlobalSettings.JPEGEngine.html


Secondly, it's probably not a major factor, but I would try it without using layers.

i.e. Load each image, draw the branding image (ensure you load it only once into a temp TIEBitmap) using:

http://www.imageen.com/help/TIEBitmap.DrawToTIEBitmap.html

Output the text:

http://www.imageen.com/help/TIECanvas.DrawText.html

Then save.


I expect when you are testing a similar process on web sites you are not taking into account the disk loading and saving times.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: