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.

Mailing lists / lazarus / 2011-04
10 messages · 4 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
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.
There is a thread talking about JPEG, TAChart and CGI here: http:/msg18414.html
Marcos Douglas
Hi guys. How to I show a picture in CGI app? I tested a fpweb demo, but, without success…
You can check the testsuite sources in the SVN repository of FPC: tests/utils/testsuite/utests.pp
Michael.
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. ^^'
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.
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.
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:
Demo:
http://silvioprog.com.br/test/antispam.php
Thx.
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).
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!
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.