[SOLVED] Image resize lazarus / 39-Graphics ---------------------------------------------------------------------- DanishMale · 2025-02-15 20:10 Hi all, I am trying to load an image and resize the image to save on another location in the target size. Target info: Height: 132 Width: 220 Aspect ratio: 1.67 Transparent after resize Keep aspect ratio from original image if width is less than target, but height is equal to target merge with empty image and center image if height is less than target, but width is equal to target merge with empty image and center image Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       OrgImage.Picture.LoadFromFile(OpenDialog1.FileName);      OrgHeight := OrgImage.Picture.Height;      OrgWidth := OrgImage.Picture.Width;    AspectRatio := OrgWidth / OrgHeight;      AspectRatio := StrToFloat(Format('%.2f', [AspectRatio]));      if AspectRatio = 1.67 then      begin   // Equals Result dimensions        NewHeight := 132;        NewWidth := 220;      end      else if AspectRatio > 1 then      begin   // Width greater than Height        NewWidth := 220;        NewHeight := Trunc(220 / AspectRatio);                if NewHeight > 132 then                begin                  NewHeight := 132;                   NewWidth := Trunc(132 * AspectRatio);              end;      end      else if AspectRatio < 1 then      begin   // Height greater than Width        NewHeight := 132;        NewWidth := Trunc(132 * AspectRatio);                if NewWidth > 220 then              begin                  NewHeight := 220;                   NewWidth := Trunc(220 / AspectRatio);                end;      end;                  // GotIT working with this code  !!!      NewImage.Height := 132;      NewImage.Width := 220;      NewTop := Trunc((132 - NewHeight) / 2);      NewLeft := Trunc((220 - NewWidth) / 2);      NewImage.Picture.Bitmap.SetSize(220,132);      NewImage.Picture.Bitmap.PixelFormat := pf32bit;      NewImage.Picture.Bitmap.TransparentColor := TColor($D30094);      NewImage.Picture.Bitmap.Canvas.Clear;      NewImage.Picture.Bitmap.Canvas.StretchDraw(Rect(NewLeft,NewTop,                                                                             NewLeft+NewWidth,NewTop+NewHeight),                                                                               OrgImage.Picture.Graphic);      NewImage.Picture.SaveToFile(LogoPath+ '\Manufacturer\'+Edit5.Text+'.png');  I have tried many other ways, however, it seems I am unable to get it working