 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ido Kanner Guest
|
Posted: Wed Sep 10, 2003 11:56 am Post subject: Stream image with CGI program |
|
|
Hello
I'm sorry for my bad english from ahed...
I'm tring to make a CGI program in pure Pascal (no use of existing
components for that) that uses the console mode output (ie writeln
('some text'); etc...).
I'm tring to make a thumbnail image out of a big images in order to make
a shorter loading of them.
I'd understood reading from other newsgroups that i need to publish a
stream containing the image.
This is my code for doing so (witch does not work):
procedure WriteStream(stream:TStream);
var
OutStream:THandleStream;
begin
Flush(output);
OutStream:=THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE));
//Stream.SaveToStream(OutStream);
OutStream.CopyFrom(Stream,Stream.Size);
OutStream.Free;
Flush(output);
end;
procedure WriteFile(FileName:string; Width, Height : Integer);
var
Img : TGraphic;
Strm : TMemoryStream;
Cnvs : TCanvas;
Rec : TRect;
begin
Cnvs := TCanvas.Create;
Strm := TMemoryStream.Create;
case ImageType(FileName) of
itBmp : begin
Img := TBitmap.Create;
TBitmap(Img).LoadFromFile(FileName);
Cnvs.Handle := TBitmap(Img).Canvas.Handle;
if Width > Img.Width then
Width := Img.Width;
if Height > Img.Height then
Height := Img.Height;
Rec := Rect(0,0,Width, Height);
Cnvs.StretchDraw(Rec,Img);
Img.Width := Width;
Img.Height := Height;
TBitmap(Img).Canvas.Assign(Cnvs);
WriteLn('Content-type: image/bmp');
end;
itGif : begin
Img := TGIFGraphic.Create;
TGIFGraphic(Img).LoadFromFile(FileName);
if Width > Img.Width then
Width := Img.Width;
if Height > Img.Height then
Height := Img.Height;
Rec := Rect(0,0,Width, Height);
Cnvs.Handle := TGIFGraphic(Img).Canvas.Handle;
Cnvs.StretchDraw(Rec,Img);
Img.Width := Width;
Img.Height := Height;
TGIFGraphic(Img).Canvas.Assign(Cnvs);
WriteLn('Content-type: image/gif');
end;
itJpg : begin
Img := TJPEGImage.Create;
TJPEGImage(Img).LoadFromFile(FileName);
if Width > Img.Width then
Width := Img.Width;
if Height > Img.Height then
Height := Img.Height;
Rec := Rect(0,0,Width, Height);
Cnvs.Handle := TBitmap(Img).Canvas.Handle;
Cnvs.StretchDraw(Rec,Img);
Img.Width := Width;
Img.Height := Height;
TBitmap(Img).Canvas.Assign(Cnvs);
WriteLn('Content-type: image/jpg');
end;
itPng : begin
Img := TPNGGraphic.Create;
TPNGGraphic(Img).LoadFromFile(FileName);
if Width > Img.Width then
Width := Img.Width;
if Height > Img.Height then
Height := Img.Height;
Rec := Rect(0,0,Width, Height);
Cnvs.Handle := TPNGGraphic(Img).Canvas.Handle;
Cnvs.StretchDraw(Rec,Img);
Img.Width := Width;
Img.Height := Height;
TPNGGraphic(Img).Canvas.Assign(Cnvs);
WriteLn('Content-type: image/png');
end;
end;
Img.SaveToStream(Strm);
WriteStream(Strm);
Img.Free;
Strm.Free;
Cnvs.Free;
end;
How can i do that currectly ? beacuse it does not publish into the
screen the images. infact it makes the output result to stop without
continue any run of the rest of the code (afther calling the WriteFile
procedure.
Thank you very much for any help you can give me.
And again i'm sorry for my bad english.
Ido Kanner
|
|
| Back to top |
|
 |
Ido Kanner Guest
|
Posted: Wed Sep 10, 2003 4:37 pm Post subject: Re: Stream image with CGI program |
|
|
Well i solved most of the problems
but there is a new problem it does not convert the data into a "real"
image, but insted it display the image content (ie binary value) and not
the as a "real" image...
Any help will be very appriciated...
This is the new code:
procedure WriteStream(stream:TStream);
var
OutStream:THandleStream;
begin
Flush(output);
OutStream:=THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE));
Stream.Position := 0;
OutStream.CopyFrom(Stream,Stream.Size);
//Flush(output);
end;
procedure WriteFile(FileName:string; Width, Height : Integer);
var
Img : TGraphic;
Strm : TMemoryStream;
Rec : TRect;
Bmp : TBitmap;
begin
Strm := TMemoryStream.Create;
Bmp := TBitmap.Create;
Img := nil;
case ImageType(FileName) of
itBmp : begin
Img := TBitmap.Create;
TBitmap(Img).LoadFromFile(FileName);
if Width > Img.Width then
Width := Img.Width;
if Height > Img.Height then
Height := Img.Height;
Rec := Rect(0,0,Width, Height);
Bmp.Width := Width;
Bmp.Height := Height;
Bmp.Canvas.StretchDraw(Rec,Img);
end;
itGif : begin
Img := TGIFGraphic.Create;
TGIFGraphic(Img).LoadFromFile(FileName);
if Width > Img.Width then
Width := Img.Width;
if Height > Img.Height then
Height := Img.Height;
Rec := Rect(0,0,Width, Height);
Bmp.Width := Width;
Bmp.Height := Height;
Bmp.Canvas.StretchDraw(Rec,Img);
end;
itJpg : begin
Img := TJPEGImage.Create;
TJPEGImage(Img).LoadFromFile(FileName);
if Width > Img.Width then
Width := Img.Width;
if Height > Img.Height then
Height := Img.Height;
Rec := Rect(0,0,Width, Height);
Bmp.Width := Width;
Bmp.Height := Height;
Bmp.Canvas.StretchDraw(Rec,Img);
end;
itPng : begin
Img := TPNGGraphic.Create;
TPNGGraphic(Img).LoadFromFile(FileName);
if Width > Img.Width then
Width := Img.Width;
if Height > Img.Height then
Height := Img.Height;
Rec := Rect(0,0,Width, Height);
Bmp.Width := Width;
Bmp.Height := Height;
Bmp.Canvas.StretchDraw(Rec,Img);
end;
end;
WriteLn('Content-type: image/bmp');
writeln;
Bmp.SaveToStream(Strm);
writeln;
WriteStream(Strm);
Img.Free;
Bmp.Free;
end;
Ido
Ido Kanner wrote:
| Quote: | Hello
I'm sorry for my bad english from ahed...
I'm tring to make a CGI program in pure Pascal (no use of existing
components for that) that uses the console mode output (ie writeln
('some text'); etc...).
I'm tring to make a thumbnail image out of a big images in order to make
a shorter loading of them.
I'd understood reading from other newsgroups that i need to publish a
stream containing the image.
This is my code for doing so (witch does not work):
procedure WriteStream(stream:TStream);
var
OutStream:THandleStream;
begin
Flush(output);
OutStream:=THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE));
//Stream.SaveToStream(OutStream);
OutStream.CopyFrom(Stream,Stream.Size);
OutStream.Free;
Flush(output);
end;
procedure WriteFile(FileName:string; Width, Height : Integer);
var
Img : TGraphic;
Strm : TMemoryStream;
Cnvs : TCanvas;
Rec : TRect;
begin
Cnvs := TCanvas.Create;
Strm := TMemoryStream.Create;
case ImageType(FileName) of
itBmp : begin
Img := TBitmap.Create;
TBitmap(Img).LoadFromFile(FileName);
Cnvs.Handle := TBitmap(Img).Canvas.Handle;
if Width > Img.Width then
Width := Img.Width;
if Height > Img.Height then
Height := Img.Height;
Rec := Rect(0,0,Width, Height);
Cnvs.StretchDraw(Rec,Img);
Img.Width := Width;
Img.Height := Height;
TBitmap(Img).Canvas.Assign(Cnvs);
WriteLn('Content-type: image/bmp');
end;
itGif : begin
Img := TGIFGraphic.Create;
TGIFGraphic(Img).LoadFromFile(FileName);
if Width > Img.Width then
Width := Img.Width;
if Height > Img.Height then
Height := Img.Height;
Rec := Rect(0,0,Width, Height);
Cnvs.Handle := TGIFGraphic(Img).Canvas.Handle;
Cnvs.StretchDraw(Rec,Img);
Img.Width := Width;
Img.Height := Height;
TGIFGraphic(Img).Canvas.Assign(Cnvs);
WriteLn('Content-type: image/gif');
end;
itJpg : begin
Img := TJPEGImage.Create;
TJPEGImage(Img).LoadFromFile(FileName);
if Width > Img.Width then
Width := Img.Width;
if Height > Img.Height then
Height := Img.Height;
Rec := Rect(0,0,Width, Height);
Cnvs.Handle := TBitmap(Img).Canvas.Handle;
Cnvs.StretchDraw(Rec,Img);
Img.Width := Width;
Img.Height := Height;
TBitmap(Img).Canvas.Assign(Cnvs);
WriteLn('Content-type: image/jpg');
end;
itPng : begin
Img := TPNGGraphic.Create;
TPNGGraphic(Img).LoadFromFile(FileName);
if Width > Img.Width then
Width := Img.Width;
if Height > Img.Height then
Height := Img.Height;
Rec := Rect(0,0,Width, Height);
Cnvs.Handle := TPNGGraphic(Img).Canvas.Handle;
Cnvs.StretchDraw(Rec,Img);
Img.Width := Width;
Img.Height := Height;
TPNGGraphic(Img).Canvas.Assign(Cnvs);
WriteLn('Content-type: image/png');
end;
end;
Img.SaveToStream(Strm);
WriteStream(Strm);
Img.Free;
Strm.Free;
Cnvs.Free;
end;
How can i do that currectly ? beacuse it does not publish into the
screen the images. infact it makes the output result to stop without
continue any run of the rest of the code (afther calling the WriteFile
procedure.
Thank you very much for any help you can give me.
And again i'm sorry for my bad english.
Ido Kanner
|
|
|
| Back to top |
|
 |
Darren Davis Guest
|
Posted: Wed Sep 10, 2003 6:37 pm Post subject: Re: Stream image with CGI program |
|
|
Check the HTTP headers you are sending back - if any - before you send the
image. The client at-least needs to know its getting an image or some sort,
not html or text.
D.
--
The supplied email address is a spam trap, I don't read any mail sent to it
and I wipe it intermittently. I may be a bit backwards but you can contact
me here: eiTODtenitTAzad
|
|
| Back to top |
|
 |
dESFasado Guest
|
Posted: Fri Oct 03, 2003 5:06 am Post subject: Re: Stream image with CGI program |
|
|
En 10 Sep 2003 11:37:50 -0700, Darren Davis <mercury (AT) oceanfree (DOT) net> escribió:
With Indy Tidhttpserver use contenttype property of TIdhttpresponseInfo class and use TidMIMETable to retrieve the MIME type.
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Oct 03, 2003 6:39 am Post subject: Re: Stream image with CGI program |
|
|
"dESFasado" <ask (AT) ciudad (DOT) com.ar> wrote
| Quote: | With Indy Tidhttpserver use contenttype property of
TIdhttpresponseInfo class and use TidMIMETable to
retrieve the MIME type.
|
If you use the server's ServeFile() method, that that is already taken care
of for you.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|