[Lazarus] How to show a picture in a CGI app?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] How to show a picture in a CGI app?

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
=============================================
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to show a picture in a CGI app?

Marcos Douglas
On Sat, Apr 2, 2011 at 10:47 AM, silvioprog <[hidden email]> wrote:
> 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://www.mail-archive.com/lazarus@.../msg18414.html

Marcos Douglas

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to show a picture in a CGI app?

Michael Van Canneyt
In reply to this post by silvioprog


On Sat, 2 Apr 2011, silvioprog wrote:

> 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.

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to show a picture in a CGI app?

silvioprog
In reply to this post by Marcos Douglas
2011/4/2 Marcos Douglas <[hidden email]>:
[....]
> There is a thread talking about JPEG, TAChart and CGI here:
> http://www.mail-archive.com/lazarus@.../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
=============================================

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to show a picture in a CGI app?

silvioprog
In reply to this post by Michael Van Canneyt
2011/4/2 Michael Van Canneyt <[hidden email]>:
> 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
=============================================

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to show a picture in a CGI app?

leledumbo
Administrator
In reply to this post by silvioprog
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.
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to show a picture in a CGI app?

silvioprog
2011/4/2 leledumbo <[hidden email]>:
> 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
=============================================

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to show a picture in a CGI app?

silvioprog
In reply to this post by silvioprog
2011/4/2 silvioprog <[hidden email]>:
[...]
>    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
=============================================

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to show a picture in a CGI app?

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
=============================================

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to show a picture in a CGI app?

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
=============================================

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus