Topic: [Script] How to resize picture before save to database

for version 4.5 and above
support jpeg, png, bmp, gif


procedure frmEmployee_bSave_OnClick (Sender: TObject; var Cancel: boolean);
var
    Filename, Path: string;
begin
    if frmEmployee.DBImage1.dbImageIsChanged then
    begin
        frmEmployee.DBImage1.dbImageIsChanged := True;
        if frmEmployee.DBImage1.Picture.Width > frmEmployee.DBImage1.Width then
        begin
            Filename := ExtractFileName(frmEmployee.DBImage1.dbFileName);
            Filename := ChangeFileExt(Filename, '.jpg');
            Path := ExtractFilePath(frmEmployee.DBImage1.dbFileName);
            if PictureResizeToJpg(frmEmployee.DBImage1.dbFileName, Path+'resized_'+Filename, frmEmployee.DBImage1.Width) then
            begin
                frmEmployee.DBImage1.Picture.LoadFromFile(Path+'resized_'+Filename);
                DeleteFile(Path+'resized_'+Filename);
            end;
        end;

    end;
end;

Project example:

Post's attachments

Attachment icon Resize Picture for DBImage.zip 150.61 kb, 95 downloads since 2018-07-10 

Dmitry.