(SOLVED) TextOut Problem lazarus / 39-Graphics ---------------------------------------------------------------------- xinyiman · 2019-10-01 08:38 Hi guys, I have to do a web application that manipulates some images. And it seems to work well, the only thing is that when I have to write something on the canvas it goes wrong. I enclose an example in which if you comment on the line containing the TextOut you will see the correct result, otherwise not. Can anyone tell me what I'm wrong? EDIT: this is url to view the page on browser localhost:8090/TFPWebModule1/image ---------------------------------------------------------------------- xinyiman · 2019-10-02 07:45 No suggestion? For those who downloaded it, can you replicate the error? ---------------------------------------------------------------------- paweld · 2019-10-02 14:50 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 unit Unit1; {$mode objfpc}{$H+} interface uses     SysUtils, Classes, httpdefs, fpHTTP, fpWeb,    Graphics,    fpimage, FPCanvas, FPImgCanv,    FPWriteJPEG,    FTFont; type   { TFPWebModule1 }   TFPWebModule1 = class(TFPWebModule)    procedure imageRequest(Sender: TObject; ARequest: TRequest;      AResponse: TResponse; var Handled: Boolean);  private   public   end; var  FPWebModule1: TFPWebModule1; implementation {$R *.lfm} { TFPWebModule1 } procedure TFPWebModule1.imageRequest(Sender: TObject; ARequest: TRequest;  AResponse: TResponse; var Handled: Boolean);var canvas    : TFPcustomCanvas;    image     : TFPCustomImage;    writer    : TFPCustomImageWriter;    MyStream  : TMemoryStream;    img_src   : string;    AFont: TFreeTypeFont;begin      img_src := ExtractFilePath(ParamStr(0)) + DirectorySeparator + 'img.jpg';      if FileExists(img_src) then     begin       AResponse.ContentType := 'image/jpeg';        FTFont.InitEngine;       FontMgr.SearchPath := ExtractFilePath(ParamStr(0));       AFont := TFreeTypeFont.Create;      image := TFPMemoryImage.Create (0,0);       image.LoadFromFile(img_src);        Canvas := TFPImageCanvas.Create (image);       Writer := TFPWriterJPEG.Create;        Canvas.Font:=AFont;       Canvas.Font.Name:='Arial';        Canvas.Brush.FPColor := TColorToFPColor(clWhite);       Canvas.Font.FPColor  := TColorToFPColor(clYellow);       Canvas.Font.Size     := 18;         Canvas.TextOut(20, 40,'Hello world'); //Comment this line to run correctly          MyStream := TMemoryStream.Create;       image.SaveToStream(MyStream, writer);     AResponse.ContentStream := MyStream;         Canvas.Free;       image.Free;       writer.Free;       AFont.Free;     end else begin     AResponse.ContentType := 'text/html';       AResponse.Contents.Text:='Image not found : ' + img_src;     end;    Handled := true;end; initialization  RegisterHTTPModule('TFPWebModule1', TFPWebModule1);end. ---------------------------------------------------------------------- xinyiman · 2019-10-03 06:35 Quote from: paweld on October 02, 2019, 04:50:15 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses     SysUtils, Classes, httpdefs, fpHTTP, fpWeb,    Graphics,    fpimage, FPCanvas, FPImgCanv,    FPWriteJPEG,    FTFont; type   { TFPWebModule1 }   TFPWebModule1 = class(TFPWebModule)    procedure imageRequest(Sender: TObject; ARequest: TRequest;      AResponse: TResponse; var Handled: Boolean);  private   public   end; var  FPWebModule1: TFPWebModule1; implementation {$R *.lfm} { TFPWebModule1 } procedure TFPWebModule1.imageRequest(Sender: TObject; ARequest: TRequest;  AResponse: TResponse; var Handled: Boolean);var canvas    : TFPcustomCanvas;    image     : TFPCustomImage;    writer    : TFPCustomImageWriter;    MyStream  : TMemoryStream;    img_src   : string;    AFont: TFreeTypeFont;begin      img_src := ExtractFilePath(ParamStr(0)) + DirectorySeparator + 'img.jpg';      if FileExists(img_src) then     begin       AResponse.ContentType := 'image/jpeg';        FTFont.InitEngine;       FontMgr.SearchPath := ExtractFilePath(ParamStr(0));       AFont := TFreeTypeFont.Create;      image := TFPMemoryImage.Create (0,0);       image.LoadFromFile(img_src);        Canvas := TFPImageCanvas.Create (image);       Writer := TFPWriterJPEG.Create;        Canvas.Font:=AFont;       Canvas.Font.Name:='Arial';        Canvas.Brush.FPColor := TColorToFPColor(clWhite);       Canvas.Font.FPColor  := TColorToFPColor(clYellow);       Canvas.Font.Size     := 18;         Canvas.TextOut(20, 40,'Hello world'); //Comment this line to run correctly          MyStream := TMemoryStream.Create;       image.SaveToStream(MyStream, writer);     AResponse.ContentStream := MyStream;         Canvas.Free;       image.Free;       writer.Free;       AFont.Free;     end else begin     AResponse.ContentType := 'text/html';       AResponse.Contents.Text:='Image not found : ' + img_src;     end;    Handled := true;end; initialization  RegisterHTTPModule('TFPWebModule1', TFPWebModule1);end.  Thank you very much