JPG,PNG,GIF转Ascii
Jun 21, 2016 am 09:05 AM
img
nbsp
rgb
这个范例可以用来图形转xpm给PHP_GTK用的,不过大家先看一下这个简单程序码,先了解原理,说xpm大概没几个知道,只好改写成这个范例。图形转Ascii。
<code><font color="#000000"><font color="#0000bb"></font><font face="新宋体" color="#007700"><br></font><font face="新宋体"><font color="#ff8000">## 转换图档<br></font><font color="#0000bb">$Pic </font><font color="#007700">= </font><font color="#dd0000">"jerry.jpg"</font></font><font face="新宋体" color="#007700">;<br></font><font face="新宋体"><font color="#ff8000">## 欲转换之字符串<br></font><font color="#0000bb">$Ascii </font><font color="#007700">= </font><font color="#dd0000">"#"</font></font><font face="新宋体"><font color="#007700">; <br><br></font><font color="#0000bb">$ImageSize</font><font color="#007700">=</font><font color="#0000bb">GetImageSize</font><font color="#007700">(</font><font color="#0000bb">$Pic</font></font><font face="新宋体"><font color="#007700">);<br><br>If(</font><font color="#0000bb">Is_Array</font><font color="#007700">(</font><font color="#0000bb">$ImageSize</font></font><font face="新宋体"><font color="#007700">)):<br> </font><font color="#0000bb">$Width </font><font color="#007700">=</font><font color="#0000bb">$ImageSize</font><font color="#007700">[</font><font color="#0000bb">0</font><font color="#007700">]; </font></font><font face="新宋体"><font color="#ff8000">## 获取宽度<br> </font><font color="#0000bb">$Height </font><font color="#007700">=</font><font color="#0000bb">$ImageSize</font><font color="#007700">[</font><font color="#0000bb">1</font><font color="#007700">]; </font></font><font face="新宋体"><font color="#ff8000">## 获取长度 <br> </font><font color="#007700">Switch(</font><font color="#0000bb">$ImageSize</font><font color="#007700">[</font><font color="#0000bb">2</font><font color="#007700">]): </font></font><font face="新宋体"><font color="#ff8000">## 判断格式,因为4是SWF,所以就没写出来<br> </font><font color="#007700">Case </font><font color="#dd0000">'1'</font></font><font face="新宋体"><font color="#007700">:<br> If(</font><font color="#0000bb">ImageTypes</font><font color="#007700">() & </font><font color="#0000bb">IMG_GIF</font></font><font face="新宋体"><font color="#007700">):<br> </font><font color="#0000bb">$img</font><font color="#007700">=</font><font color="#0000bb">ImageCreateFromGIF</font><font color="#007700">(</font><font color="#0000bb">$Pic</font></font><font face="新宋体"><font color="#007700">); <br> Else:<br> Exit(</font><font color="#dd0000">"系统不支持GIF格式图档"</font></font><font face="新宋体"><font color="#007700">);<br> EndIf;<br> Break;<br> Case </font><font color="#dd0000">'2'</font></font><font face="新宋体"><font color="#007700">:<br> If(</font><font color="#0000bb">ImageTypes</font><font color="#007700">() & </font><font color="#0000bb">IMG_JPG</font></font><font face="新宋体"><font color="#007700">):<br> </font><font color="#0000bb">$img</font><font color="#007700">=</font><font color="#0000bb">ImageCreateFromJPEG</font><font color="#007700">(</font><font color="#0000bb">$Pic</font></font><font face="新宋体"><font color="#007700">);<br> Else:<br> Exit(</font><font color="#dd0000">"系统不支持JPG格式图档"</font></font><font face="新宋体"><font color="#007700">);<br> EndIf;<br> Break;<br> Case </font><font color="#dd0000">'3'</font></font><font face="新宋体"><font color="#007700">:<br> If(</font><font color="#0000bb">ImageTypes</font><font color="#007700">() & </font><font color="#0000bb">IMG_PNG</font></font><font face="新宋体"><font color="#007700">):<br> </font><font color="#0000bb">$img</font><font color="#007700">=</font><font color="#0000bb">ImageCreateFromPNG</font><font color="#007700">(</font><font color="#0000bb">$Pic</font></font><font face="新宋体"><font color="#007700">);<br> Else:<br> Exit(</font><font color="#dd0000">"系统不支持PNG格式图档"</font></font><font face="新宋体"><font color="#007700">);<br> EndIf;<br> Break;<br> Default:<br> Exit(</font><font color="#dd0000">"系统无法辨识"</font></font><font face="新宋体"><font color="#007700">);<br> Break;<br> EndSwitch;<br> For(</font><font color="#0000bb">$y</font><font color="#007700">=</font><font color="#0000bb">1</font><font color="#007700">;</font><font color="#0000bb">$y</font><font color="#007700"><font color="#0000bb">$Height</font><font color="#007700">;</font><font color="#0000bb">$y</font></font><font face="新宋体"><font color="#007700">++):<br> For(</font><font color="#0000bb">$x</font><font color="#007700">=</font><font color="#0000bb">1</font><font color="#007700">;</font><font color="#0000bb">$x</font><font color="#007700"><font color="#0000bb">$Width</font><font color="#007700">;</font><font color="#0000bb">$x</font></font><font face="新宋体" color="#007700">++):<br> </font><font face="新宋体"><font color="#ff8000">## 取点索引<br> </font><font color="#0000bb">$index </font><font color="#007700">= </font><font color="#0000bb">ImageColorAt</font><font color="#007700">(</font><font color="#0000bb">$img</font><font color="#007700">,</font><font color="#0000bb">$x</font><font color="#007700">,</font><font color="#0000bb">$y</font></font><font face="新宋体" color="#007700">); <br> </font><font face="新宋体"><font color="#ff8000">## 获取RGB颜色<br> </font><font color="#0000bb">$rgb </font><font color="#007700">= </font><font color="#0000bb">ImageColorsForIndex</font><font color="#007700">(</font><font color="#0000bb">$img</font><font color="#007700">,</font><font color="#0000bb">$index</font></font><font face="新宋体" color="#007700">);<br> </font><font face="新宋体"><font color="#ff8000">## 255,255,255(RGB)转FFFFFF(HTML用的)此种格式<br> </font><font color="#0000bb">$color </font><font color="#007700">= </font><font color="#0000bb">dechex</font><font color="#007700">(</font><font color="#0000bb">$rgb</font><font color="#007700">[</font><font color="#0000bb">red</font><font color="#007700">]).</font><font color="#0000bb">dechex</font><font color="#007700">(</font><font color="#0000bb">$rgb</font><font color="#007700">[</font><font color="#0000bb">green</font><font color="#007700">]).</font><font color="#0000bb">dechex</font><font color="#007700">(</font><font color="#0000bb">$rgb</font><font color="#007700">[</font><font color="#0000bb">blue</font></font><font face="新宋体"><font color="#007700">]); <br> Echo </font><font color="#dd0000">"<font>$Ascii</font>"</font></font><font face="新宋体"><font color="#007700">; <br> EndFor;<br> Echo </font><font color="#dd0000">"<br>"</font></font><font face="新宋体"><font color="#007700">;<br> EndFor;<br>EndIf;<br></font><font color="#0000bb">?></font></font></font></font></font> |
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution: Your organization requires you to change your PIN

How to adjust window border settings on Windows 11: Change color and size

How to change title bar color on Windows 11?

How to enable or disable taskbar thumbnail previews on Windows 11

OOBELANGUAGE Error Problems in Windows 11/10 Repair

10 Ways to Adjust Brightness on Windows 11
