Jump to content
FHannes

Resize JPEGs

Recommended Posts

I had to resize a lot of JPEG's to a long edge of 1000 pix and a thumbnail with a long edge of 200pix. If anyone is interested, here's the script I wrote to do it for me:

[scar]var

Files: TStrArray;

Idx, Len: Integer;

Bmp: TSCARBitmap;

NewWidth, NewHeight, ThumbWidth, ThumbHeight: Integer;

 

begin

Files := GetFiles(ScriptPath, 'jpg');

Len := Length(Files);

for Idx := 0 to Len - 1 do

begin

Bmp := TSCARBitmap.Create('');

try

Bmp.LoadFromJpeg(ScriptPath + Files[idx]);

if Bmp.Width > Bmp.Height then

begin

NewWidth := 1000;

NewHeight := Bmp.Height * 1000 div Bmp.Width;

ThumbWidth := 200;

ThumbHeight := Bmp.Height * 200 div Bmp.Width;

end else begin

NewWidth := Bmp.Width * 1000 div Bmp.Height;

NewHeight := 1000;

ThumbWidth := Bmp.Width * 200 div Bmp.Height;

ThumbHeight := 200;

end;

Bmp.Resize(NewWidth, NewHeight);

Bmp.SaveToJpeg(ScriptPath + 'output\' + Copy(Files[idx], 1,

Length(Files[idx]) - Length(ExtractFileExt(Files[idx]))) + '.jpg', 95);

Bmp.Resize(ThumbWidth, ThumbHeight);

Bmp.SaveToJpeg(ScriptPath + 'output\' + Copy(Files[idx], 1,

Length(Files[idx]) - Length(ExtractFileExt(Files[idx]))) + '-thumb.jpg', 95);

finally

Bmp.Free;

end;

Status(IntToStr(Idx + 1) + '/' + IntToStr(Len));

end;

Status('Done');

end.[/scar]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...