?? perl 語言-perl 中文教程(第一章cgilib例).htm
字號:
<TR>
<TD><A onmouseover="MM_swapImage('Image12','','8a.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://www.sun126.com/perl5/perl5-8.htm"><IMG
src="Perl 語言-Perl 中文教程(第一章cgilib例).files/8.gif" border=0
name=Image12></A></TD></TR>
<TR>
<TD><A onmouseover="MM_swapImage('Image13','','9a.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://www.sun126.com/perl5/perl5-16.htm#"><IMG
src="Perl 語言-Perl 中文教程(第一章cgilib例).files/9.gif" border=0
name=Image13></A></TD></TR>
<TR>
<TD><A onmouseover="MM_swapImage('Image14','','10a.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://www.sun126.com/perl5/perl5-10.htm"><IMG
src="Perl 語言-Perl 中文教程(第一章cgilib例).files/10.gif" border=0
name=Image14></A></TD></TR>
<TR>
<TD><A onmouseover="MM_swapImage('Image15','','11a.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://www.sun126.com/perl5/perl5-11.htm"><IMG
src="Perl 語言-Perl 中文教程(第一章cgilib例).files/11.gif" border=0
name=Image15></A></TD></TR>
<TR>
<TD><A onmouseover="MM_swapImage('Image17','','12a.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://www.sun126.com/perl5/perl5-12.htm"><IMG
src="Perl 語言-Perl 中文教程(第一章cgilib例).files/12.gif" border=0
name=Image17></A></TD></TR>
<TR>
<TD><A onmouseover="MM_swapImage('Image16','','13a.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://www.sun126.com/perl5/perl5-13.htm"><IMG
src="Perl 語言-Perl 中文教程(第一章cgilib例).files/13.gif" border=0
name=Image16></A></TD></TR>
<TR>
<TD><A onmouseover="MM_swapImage('Image18','','14a.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://www.sun126.com/perl5/perl5-14.htm"><IMG
src="Perl 語言-Perl 中文教程(第一章cgilib例).files/14.gif" border=0
name=Image18></A></TD></TR>
<TR>
<TD><A onmouseover="MM_swapImage('Image19','','y1a.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://www.sun126.com/perl5/perl5-15.htm"><IMG
src="Perl 語言-Perl 中文教程(第一章cgilib例).files/y1.gif" border=0
name=Image19></A></TD></TR>
<TR>
<TD><A onmouseover="MM_swapImage('Image20','','y2a.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://www.sun126.com/perl5/perl5-16.htm"><IMG
src="Perl 語言-Perl 中文教程(第一章cgilib例).files/y2.gif" border=0
name=Image20></A></TD></TR>
<TR>
<TD><A onmouseover="MM_swapImage('Image21','','y3a.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://www.sun126.com/perl5/perl5-17.htm"><IMG
src="Perl 語言-Perl 中文教程(第一章cgilib例).files/y3.gif" border=0
name=Image21></A></TD></TR></TBODY></TABLE></TD>
<TD class=myFont vAlign=top width=30><IMG height=1
src="Perl 語言-Perl 中文教程(第一章cgilib例).files/x.gif" width=10> </TD>
<TD class=myFont vAlign=top>
<DIV align=center><IMG height=30
src="Perl 語言-Perl 中文教程(第一章cgilib例).files/top.gif" width=180><BR><SPAN
class=myFont><SPAN class=myFont><FONT face=宋體>翻譯:</FONT></SPAN></SPAN>
<SPAN class=myFont><SPAN class=myFont>flamephoenix</SPAN></SPAN> <BR>
<HR width="100%" SIZE=1>
<DIV align=left>
<P align=center><B>第二章 動態創建圖象(未定稿)</B></P>
<P><BR> “動態文檔”不僅指文本,CGI程序可以創建圖象、聲音等各種媒體。你只須輸出相應的MIME頭、一行空行及原始數據即可。<BR> 下例的image.cgi將裝載一個GIF圖像文件并送到瀏覽器顯示:
</P>
<BLOCKQUOTE>
<P>#!/usr/bin/perl<BR><BR>$file =
'/usr/local/etc/httpd/htdocs/images/picture.gif';<BR><BR>print
"Content-Type: image/gif\n\n";<BR>open(GIF,"<$file") || die "Can't
open GIF\n"; <BR>while (read(GIF,$buffer,16384)) {<BR> print
$buffer;<BR>} </P></BLOCKQUOTE>
<P> image.cgi首先發送MIME頭說明(Content-Type),然后讀取文件內容并輸出。這段程序對$file變量和Content-Type類型略加修改就可以發送聲音或影像文件。<BR> 那么怎樣把CGI程序創建的圖像嵌到頁面中呢?SSI是不行的,方法是用<img>標簽,語法如:<BR> <img
src="/cgi-bin/image.cgi"><BR> 僅就顯示picture.gif這幅圖像而言,用上述的image.cgi是沒有什么意義的,更恰當的方式是這樣使用:<BR> <img
src="/images/picture.gif"><BR> 但是,image.cgi可以擴展功能來做更多的事。例如它可以從多個圖像文件中隨即地選擇一個來顯示,那么,每一次訪問該頁面時都會出現不同的圖像。<BR> 計數器程序通常利用<img>標簽的這一特性,尤其是那些不允許解析HTML和SSI的服務器特別實用。服務器端不解析HTML文件可以降低服務器的負載。<BR> 此外,除了簡單的裝載并顯示已有的圖像文件外,可以真正的動態生成所需的圖像。你可以設計一個CGI程序根據不同的參數及用戶定義的一些細節來實時創建相應的圖像(如圖表)并顯示。這種程序的復雜性在于圖像的生成而不在于將圖像輸出給瀏覽器。幸運的是,有一些庫提供了這樣的接口,如Thomas
boutell的gd圖像庫,這是生成GIF圖像的一個出色工具,可以從<A href="http://www.boutell.com/gd/"
target=_blank>http://www.boutell.com/gd/</A>來下載。它是用C語言寫的,但是有Perl接口庫<A
href="http://www-genome.wi.mit.edu/ftp/pub/software/WWW/GD.html"
target=_blank>gd.pm</A>,還有基于gd支持多種語言的接口庫<A
href="http://s27w007.pswfs.gov/tgd/" target=_blank>tgd</A>和<A
href="http://www.unimelb.edu.au/fly/fly.html"
target=_blank>fly</A>。詳細情況見上述gd主頁。<BR> 下面是一個簡單的用位圖動態生成圖像的計數器程序,對理解上述描述應該會有所幫助。(<A
href="http://www.sun126.com/perl5/count.zip">源代碼下載</A>)<BR> 您是第<IMG
src="">位訪問本網頁的人。<BR><BR>附:GIF的說明<BR> 現在流行著一種趨勢,即遠離GIF格式而采用Portable
Network
Graphic格式(PNG),這種變化出于技術和法律兩個方面的考慮。1995年1月1日,Unisys聲稱他們有權要求使用LZW壓縮算法的軟件公司要經過他們的許可或付給他們報酬,因為他們擁有專利使用權。而GIF格式正是使用這種算法。所以,你所編寫的任何用于商業應用程序中的GIF圖像(包括以CGI/WWW為基礎的那些文件),都必須購買許可證或支付費用。許多軟件包不再壓縮GIF文件(這樣會使圖像變得很大),或者把GIF文件及其支持軟件全部去掉。PNG使用非專利的壓縮算法,從而避免了這些麻煩。在技術方面,PNG提供了較好的壓縮算法(無損失,像GIF一樣,但不像JPEG。JPEG在壓縮時會丟失數據)、二維交互以及24位和48位真彩支持?,F在,很少有瀏覽器支持內插的PNG圖像,但不久的將來,這種情況很可能會改變。GD圖形庫文件說明了PNG支持即將來臨。<BR></P></DIV></DIV></TD></TR></TBODY></TABLE>
<DIV align=center></DIV>
<DIV align=center><BR></DIV>
<DIV align=center><SPAN class=myFont><A
href="http://www.sun126.com/perl5/perl5-15-1.htm">上頁</A> <A
href="http://www.sun126.com/perl5/perl5-17.htm">下頁</A> <A
href="http://www.sun126.com/perl5/perl5index.htm">回目錄</A> <A
href="http://www.sun126.com/perl5/perl5-16.htm#a"><FONT face="Arial, 宋體">Go
Top</FONT></A></SPAN><BR><BR></DIV>
<TABLE height=50 cellSpacing=0 cellPadding=0 width="100%" bgColor=#000000
border=0>
<TBODY>
<TR>
<TD bgColor=#cccc99 height=4>
<DIV align=center><IMG height=4 src="" width=4></DIV></TD></TR>
<TR>
<TD height=50>
<DIV align=center><FONT class=myfont size=2><SPAN class=myfont><FONT
color=#99cc99><A href="http://www.sun126.com/bbs/ccb/index.cgi"><FONT
color=#99cc99>中國CCB論壇</FONT></A> 整理 麻辣
2003.7.10</FONT></SPAN></FONT><FONT class=myfont color=#99cc99
size=2><SPAN class=myfont><FONT
color=#99cc66><BR></FONT></SPAN></FONT><SPAN class=myfont><FONT
class=myfont><SPAN class=myfont><FONT face="Arial, Helvetica, sans-serif"
color=#99cc99>© 2000
http://www.sun126.com</FONT></SPAN></FONT></SPAN></DIV></TD></TR></TBODY></TABLE></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -