Thumbnails lazarus / 39-Graphics ---------------------------------------------------------------------- TRNelson · 2016-03-25 18:31 I want to create a small function will generate a thumbnail from an image file.  It seems very straightforward.  The following code seems to work well for JPEG files. 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 var  MyPicture                            : TJpegImage;  Thumbnail                          : TJpegImage;begin  MyPicture := TJpegImage.Create;  Thumbnail := TJpegImage.Create;  try    MyPicture.LoadFromFile(some jpeg file);    ThumbNail.Width  := 100;    ThumbNail.Height := 100;  ThumbNail.Canvas.StretchDraw(Rect(0, 0, 100, 100), MyPicture);    Thumbnail.SaveToFile(thumbnail jpeg file);  finally    MyPicture.Free;    Thumbnail.Free;  end;end; And that would pretty much be it.  However, I want to make it a little more general so that it can do its stuff with different graphic formats (eg: PNG, TIFF, BMP and other supported formats).  It was suggested in some online documentation that you could use TPicture.  The thumbnail would be a JPEG file.  A slight modification to the code would be required. 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 var  MyPicture                            : TPicture;  Thumbnail                          : TJpegImage;begin  MyPicture := TPicture.Create;  Thumbnail := TJpegImage.Create;  try    MyPicture.LoadFromFile(some jpeg file);    ThumbNail.Width  := 100;    ThumbNail.Height := 100;  ThumbNail.Canvas.StretchDraw(Rect(0, 0, 100, 100), MyPicture);    Thumbnail.SaveToFile(thumbnail jpeg file);  finally    MyPicture.Free;    Thumbnail.Free;  end;end; The compiler complains about incompatible types for StretchDraw.  Probably missing something very fundamental here but I can't see it. ---------------------------------------------------------------------- Mando · 2016-03-25 19:14 Hi: Try this: 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  ThumbNail.Canvas.StretchDraw(Rect(0, 0, 100, 100), MyPicture.graphic);  However, your code obtains square images (100x100), regardless of  the aspect of the original image. I had this code: 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 var   escX, escY: Extended;  img:TJPEGImage;  min:TJPEGImage;    r: TRect;begin   img:=TJPEGImage.Create; min:=TJPEGImage.Create;   img.LoadFromFile((fichero));                      escX:=400/img.width; escY:=300/img.height; if escX>escY then escX:=escY;   min.SetSize(round(img.width*escX),round(img.Height*escX));  r:=Rect(0,0,min.Width,min.height);  min.Canvas.AntialiasingMode:=amON;  min.Canvas.StretchDraw(r,img);...  regards. ---------------------------------------------------------------------- TRNelson · 2016-03-25 19:51 Well there you go!    Thanks for that.  Not sure how I missed that. As far as the squareness of the thumbnails, I was just setting up an example.  The final program will maintain the aspect ratios. Thanks again!