📄 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位真彩支持。现在,很少有浏览器支持内插的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 + -