Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-04

How to show a picture in a CGI app?

10 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hi guys.

How to I show a picture in CGI app?

I tested a fpweb demo, but, without success (acess violation):

C:\lazarus\components\fpweb\demo\image

Lazarus 0.9.31 r30005 FPC 2.5.1 i386-win32-win32/win64 / XAMPP 1.7.3

Thx.

Silvio Cl?cio ============================================= Blog - silvioprog.com.br Twitter - twitter.com/silvioprog LazSolutions - code.google.com/p/lazsolutions Lazarus-BR - groups.google.com.br/group/lazarus-br?hl=pt-BR =============================================

Reply by email

Marcos Douglas
to silvioprog
silvioprog wrote 9 lines
Hi guys. How to I show a picture in CGI app? I tested a fpweb demo, but, without success (acess violation): C:\lazarus\components\fpweb\demo\image Lazarus 0.9.31 r30005 FPC 2.5.1 i386-win32-win32/win64 / XAMPP 1.7.3

There is a thread talking about JPEG, TAChart and CGI here: http:/msg18414.html

Marcos Douglas

Reply by email

Michael Van Canneyt
to silvioprog: Hi guys. How to I show a picture in CGI app? I tested a fpweb demo, but, without success…
silvioprog wrote 9 lines
Hi guys. How to I show a picture in CGI app? I tested a fpweb demo, but, without success (acess violation): C:\lazarus\components\fpweb\demo\image Lazarus 0.9.31 r30005 FPC 2.5.1 i386-win32-win32/win64 / XAMPP 1.7.3

You can check the testsuite sources in the SVN repository of FPC: tests/utils/testsuite/utests.pp

Michael.

Reply by email

silvioprog
to Marcos Douglas: There is a thread talking about JPEG, TAChart and CGI here: http:/msg18414.html Marcos…

2011/4/2 Marcos Douglas :
[....]

There is a thread talking about JPEG, TAChart and CGI here: http:/msg18414.html Marcos Douglas

I read all posts, but I could not load the picture from a file. :(

ps. Sorry for my translation. ^^'

Silvio Cl?cio ============================================= Blog - silvioprog.com.br Twitter - twitter.com/silvioprog LazSolutions - code.google.com/p/lazsolutions Lazarus-BR - groups.google.com.br/group/lazarus-br?hl=pt-BR =============================================

Reply by email

silvioprog
to Michael Van Canneyt: You can check the testsuite sources in the SVN repository of FPC:…

2011/4/2 Michael Van Canneyt :

You can check the testsuite sources in the SVN repository of FPC: tests/utils/testsuite/utests.pp Michael.

Yes. Please, see my incomplete code:

[code]
var
  VFPMemoryImage: TFPMemoryImage;
begin
  Handled := True;
  VFPMemoryImage := TFPMemoryImage.Create(48, 48);
  try
    VFPMemoryImage.LoadFromFile('C:\lazarus\images\ide_icon48x48.png', ???);
    VFPMemoryImage.SaveToStream(AResponse.ContentStream, ???);
    AResponse.ContentType := 'image/png';
    AResponse.ContentLength := AResponse.ContentStream.Size;
    AResponse.SendContent;
  finally
    VFPMemoryImage.Free;
  end;
end;
[/code]

??? = My big doubt.

Silvio Cl?cio ============================================= Blog - silvioprog.com.br Twitter - twitter.com/silvioprog LazSolutions - code.google.com/p/lazsolutions Lazarus-BR - groups.google.com.br/group/lazarus-br?hl=pt-BR =============================================

Reply by email

leledumbo
to silvioprog: 2011/4/2 Marcos Douglas : [....] I read all posts, but I could not load the picture from…

Would you like to download or display the picture? For displaying, you should use standard HTML's img tag. For downloading, the thread pointed by marcos has an example.

View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-How-to-show-a-picture-in-a-CGI-app-tp2767228p2767526.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

silvioprog
to leledumbo

2011/4/2 leledumbo :

Would you like to download or display the picture? For displaying, you should use standard HTML's img tag. For downloading, the thread pointed by marcos has an example.

I need to read an picture from a file and write directly in the headers (to create a antispam module). :/

Code in PHP:

http://pastebin.com/NTEcrJeZ

Demo:

http://silvioprog.com.br/test/antispam.php

Thx.

Silvio Cl?cio ============================================= Blog - silvioprog.com.br Twitter - twitter.com/silvioprog LazSolutions - code.google.com/p/lazsolutions Lazarus-BR - groups.google.com.br/group/lazarus-br?hl=pt-BR =============================================

Reply by email

silvioprog
to silvioprog: 2011/4/2 Michael Van Canneyt : Yes. Please, see my incomplete code: [code] var…

2011/4/2 silvioprog :
[...]

? ?VFPMemoryImage.LoadFromFile('C:\lazarus\images\ide_icon48x48.png', ???);

I can paint in fpmemoryimage via canvas, but I also need to paint in fpmemoryimage via external files (PNGs).

Silvio Cl?cio ============================================= Blog - silvioprog.com.br Twitter - twitter.com/silvioprog LazSolutions - code.google.com/p/lazsolutions Lazarus-BR - groups.google.com.br/group/lazarus-br?hl=pt-BR =============================================

Reply by email

silvioprog
to silvioprog

YES! :}D

This code (from "C:\lazarus\components\fpweb\demo\image") works for me:

[code]
var
  OFN, FN: string;
  F: TFileStream;
begin
  Handled := True;
  OFN := 'C:\lazarus\images\actions\arrow_down.png';
  FN := OFN;
  if (FN = '') then
    raise Exception.Create('This script requires a file name argument');
  // Strip any directory path.
  FN := ExtractFileName(FN);
  // Make sure it is a PNG file.
  FN := ChangeFileExt(FN, '.png');
  FN := IncludeTrailingPathDelimiter(ImageDir) + FN;
  if not FileExistsUTF8(FN) then
    raise Exception.Create('The requested file "' + OFN +
      '" does not exist in the image directory');
  AResponse.ContentType := 'image/png';
  F := TFileStream.Create(UTF8ToSys(FN), fmOpenRead);
  try
    AResponse.ContentStream := F;
    AResponse.SendContent;
    Handled := True;
  finally
    F.Free;
  end;
end;
[/code]

To use:

http://localhost/cgi-bin/imagedemo.cgi/file

The result is a picture without link, perfect to antispam generators.

Please, sorry for my ignorance. ^^

Thx to all!

Silvio Cl?cio ============================================= Blog - silvioprog.com.br Twitter - twitter.com/silvioprog LazSolutions - code.google.com/p/lazsolutions Lazarus-BR - groups.google.com.br/group/lazarus-br?hl=pt-BR =============================================

Reply by email

silvioprog
to silvioprog

Resumed code:

[code]
uses

  Classes, FileUtil, HTTPDefs, fpWeb, fpHTTP;
var
  VFileStream: TFileStream;
begin
  VFileStream := TFileStream.Create(
    UTF8ToSys('C:\lazarus\images\ide_icon48x48.png' { Or your picture.
}), fmOpenRead);
  try
    AResponse.ContentType := 'image/png';
    AResponse.ContentStream := VFileStream;
    AResponse.SendContent;
    Handled := True;
  finally
    VFileStream.Free;
  end;
end;
[/code]

Thx again.

Silvio Cl?cio ============================================= Blog - silvioprog.com.br Twitter - twitter.com/silvioprog LazSolutions - code.google.com/p/lazsolutions Lazarus-BR - groups.google.com.br/group/lazarus-br?hl=pt-BR =============================================

Reply by email