php,java,设计,都是相通有趣的哦!

[转贴]本人欣赏这个“钢笔手写体生成”功能

上一篇 / 下一篇  2007-05-05 23:18:38 / 个人分类:技术

这个网友的功能实现很好玩,虽然这样的钢笔字我不喜欢,但是功能的想法效果还是很值得学习借鉴的。报着学习的态度转贴别人的blog。张先生更象个全才,很实在的技术。羡慕中!真是自愧不如啊。。。。。
 http://blog.s135.com/read.php/237.htm
PHP程序+GD库+TTF字体编写的一款Web版《钢笔手写体生成工具 V1.0》。源代码公开。

  演示网址(可在该网址在线生成钢笔手写体文章PNG图片):

  http://www.s135.com/font/

  源代码及字体完整压缩包下载:
  http://ishare.iask.sina.com.cn/cgi-bin/fileid.cgi?fileid=1574974
  //但是不知道为什么我无法下载,我用的是linux下的ubuntu操作系统,firefox来下的。只能下到一半就突然完成可是却失败无法打开了。各位网友有没有谁下得到了,记得加我QQ35830757或者发一份给我,我的邮箱:jinbu2002cn@yahoo.com.cn。心存感激中!!
 
  主体PHP程序源代码(index.php):
  1. <?php  
  2. /* 
  3. * 文件名称:index.php 
  4. * 摘    要:钢笔手写体生成工具 
  5. * 作    者:回忆未来[张宴] 
  6. * 博    客:blog.s135.com 
  7. * 演    示:s135.com/font/ 
  8. * 版    本:1.0 
  9. * 时    间:2007-05-05 
  10. */  
  11. $text = $_POST["text"];  
  12. if ($text != "")  
  13. {  
  14.     $text = explode("\r\n"$text);  
  15.     $text_temp = "";  
  16.     $t = 0;  
  17.     foreach ($text as $key => $value)  
  18.     {  
  19.         $text_split = str_split($value, 50);  
  20.         foreach ($text_split as $key_split => $value_split)  
  21.         {  
  22.             $text_temp[$t] = $value_split;  
  23.             $t++;  
  24.         }  
  25.     }  
  26.     $text = $text_temp;  
  27.   
  28.     $text_count = count($text);  
  29.   
  30.     $fontname = "FZJLJT.FON";  
  31.     $im = imagecreate(600, $text_count * 29);  
  32.     $white = ImageColorAllocate($im, 255, 255, 255);  
  33.     $black = ImageColorAllocate($im, 0, 0, 0);  
  34.     $red = ImageColorAllocate($im, 255, 0, 0);  
  35.   
  36.     for ($n = 0; $n < $text_count$n++)  
  37.     {  
  38.         $value = $text[$n];  
  39.         $value_length = strlen($value);  
  40.         $value_count = 0;  
  41.         for ($i = 0; $i < $value_length$i++)  
  42.         {  
  43.             if (ord($value{$i}) > 127)  
  44.             {  
  45.                 $value_count++;  
  46.             }  
  47.         }  
  48.         if ($value_count % 2 != 0)  
  49.         {  
  50.             //$text[$n] = substr($value, 0, $value_length - 1);  
  51.             //$text[$n + 1] = substr($value, -1, 1) . $text[$n + 1];  
  52.             $text[$n] = $value . substr($text[$n + 1], 0, 1);  
  53.             $text[$n + 1] = substr($text[$n + 1], 1, strlen($text[$n + 1]) - 1);  
  54.         }  
  55.     }  
  56.     $text = implode("\r\n"$text);  
  57.     for ($n = 0; $n <= 1; $n++)  
  58.     {  
  59.         ImageTTFText($im, 18, 0, 2, 30, $black$fontname, iconv("GBK""UTF-8"$text));  
  60.     }  
  61.     $dir = "images/";  
  62.     if (is_dir($dir))  
  63.     {  
  64.         if ($dh = opendir($dir))  
  65.         {  
  66.             while (($file = readdir($dh)) !== false)  
  67.             {  
  68.                 if (filetype($dir . $file) == "file")  
  69.                 {  
  70.                     unlink($dir . $file);//删除文件  
  71.                 }  
  72.             }  
  73.             closedir($dh);  
  74.         }  
  75.     }  
  76.     $file_name = $dir . md5($text) . ".png";  
  77.     ImagePng($im$file_name);  
  78.     ImageDestroy($im);  
  79. }  
  80. else  
  81. {  
  82.     $file_name = "welcome.png";  
  83. }  
  84. ?>  
  85. <html>  
  86. <head>  
  87. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  88. <title>钢笔手写体生成工具 V1.0</title>  
  89. </head>  
  90. <body bgcolor="#000000">  
  91. <center>  
  92. <form id="form1" name="form1" method="post" action="">  
  93. <label>  
  94. <font color="#FFFFFF">钢笔手写体生成工具 V1.0 by 回忆未来[张宴]</font><BR />  
  95. </label>  
  96. <label>  
  97. <textarea name="text" cols="82" rows="15" id="text"></textarea>  
  98. <BR />  
  99. </label>  
  100. <label>  
  101. <input name="提交" type="submit" value="生成钢笔手写体" /><BR />  
  102. </label>   
  103. </form>  
  104. <font color="#FFFFFF" size="2">请在下图上点击鼠标右键,选择“图片另存为”将生成的钢笔手写体PNG图片保存到本地。本站不作保存。</font><br>  
  105. <img src="<?= $file_name ?>" border="0">  
  106. </center>  
  107. </body>  
  108. </html> 


TAG: 技术

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

数据统计

  • 访问量: 40971
  • 日志数: 107
  • 图片数: 3
  • 书签数: 1
  • 建立时间: 2007-03-03
  • 更新时间: 2007-12-18

RSS订阅

Open Toolbar