<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>邪罗刹的菠萝阁 &#187; image</title>
	<atom:link href="http://www.rainmoe.com/tag/image/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rainmoe.com</link>
	<description>One code, one world ...</description>
	<lastBuildDate>Thu, 29 Dec 2011 14:04:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>一个PR图片调用API与查询的程序</title>
		<link>http://www.rainmoe.com/2010/03/23/google-pr-img-api-v1/</link>
		<comments>http://www.rainmoe.com/2010/03/23/google-pr-img-api-v1/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 21:33:52 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[作品 [Work]]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[pr]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1945</guid>
		<description><![CDATA[> 嘿嘿，这个是 超人 特别版喔，送给超人童鞋。并附带用户查询界面，为其中的 Index.php 文件。

> 最近觉得 Google 很厚道，日历 阅读器 GMail GoogleCode Appengine 等一系列服务都很不错。



<span class="readmore"><a href="http://www.rainmoe.com/2010/03/23/google-pr-img-api-v1/" title="一个PR图片调用API与查询的程序">阅读全文——共462字</a></span>]]></description>
			<content:encoded><![CDATA[<p>> 嘿嘿，这个是 <a target='_blank' rel='nofollow' href='http://www.superm.org/'>超人</a> 特别版喔，送给超人童鞋。并附带用户查询界面，为其中的 Index.php 文件。<br />
> 最近觉得 Google 很厚道，日历 阅读器 GMail GoogleCode Appengine 等一系列服务都很不错。</p>
<p><img src='http://www.rainmoe.com/wp-content/uploads/old/Cap0000254.png' /></p>
<p>> 很爽，嘻嘻 O(∩_∩)O。最近打算搞一个 VPS 之类的有更大流量的东东来玩，嘎嘎，春哥保佑。<br />
> 迟一些再发布 AlexImgAPI V1.0.0 吧，其实是还没有完成啦 ╮(╯▽╰)╭，还是代码丢失的老原因。</p>
<p><span id="more-1945"></span><strong>一. GooglePRImgAPI V1.0.0：</strong></p>
<p>> 下面两幅图分别是 Index.php 和 Pr.php 的浏览图，请注意 Index.php 是依赖于 Pr.php 的喔。</p>
<p><img src='http://www.rainmoe.com/wp-content/uploads/old/Cap0000255.png' /></p>
<p><img src='http://www.rainmoe.com/wp-content/uploads/old/Cap0000256.png' /></p>
<p>> 下载 - <a target='_blank' rel='nofollow' href='http://code.google.com/p/evlosbox/downloads/detail?name=share_primgapi_UI.zip&#038;can=2&#038;q='>http://code.google.com/p/evlosbox/downloads/detail?name=share_primgapi_UI.zip</a></p>
<p><strong>二. 附言：</strong></p>
<p>> 嘿嘿，因为超人童鞋急需，所以先发布这篇，下篇将发布《WP用于围观某评论者发言的插件》。</p>
<p><img src='http://www.rainmoe.com/wp-content/uploads/old/Cap0000260.png' /></p>
<p>> 刚刚到手了 Zxc.im nnd.im，嘎嘎嘎，第一个网址是键盘上顺序按键，第二个是NND，O(∩_∩)O。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rainmoe.com/2010/03/23/google-pr-img-api-v1/feed/</wfw:commentRss>
		<slash:comments>180</slash:comments>
		</item>
		<item>
		<title>使用jQuery添加图片载入提示</title>
		<link>http://www.rainmoe.com/2009/12/27/images-loading/</link>
		<comments>http://www.rainmoe.com/2009/12/27/images-loading/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 04:18:43 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[代码 [Code]]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[loading]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1854</guid>
		<description><![CDATA[> 因为不可抗拒的因素，小邪昨天下午和今天上午都在离地球上最近的电脑有11公里的地方。

> 终于，在春哥的保佑之下，小邪终于在今天下午回到了我可爱的电脑面前。



<span class="readmore"><a href="http://www.rainmoe.com/2009/12/27/images-loading/" title="使用jQuery添加图片载入提示">阅读全文——共1855字</a></span>]]></description>
			<content:encoded><![CDATA[<p>> 因为不可抗拒的因素，小邪昨天下午和今天上午都在离地球上最近的电脑有11公里的地方。<br />
> 终于，在春哥的保佑之下，小邪终于在今天下午回到了我可爱的电脑面前。</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/Capture09391.jpg" /></p>
<p>> 呵呵，这篇文章讲的东西灰常简单，因为昨天没法一日一博，只好今天早晚各一篇。<br />
> 以弥补各位看官受伤的心灵，小邪可是很善良的喔 (*^__^*) ，哇卡卡卡卡 O(∩_∩)O。</p>
<p><span id="more-1854"></span><strong>1. 图片载入提示 Demo 传送门：</strong></p>
<p>> 小邪已经使用 Opera Safari Firefox Chrome IE6 测试过图片载入提示的代码了。<br />
> 现在浏览器缓存机制十分强大，所以如果想多次浏览，请使用 Ctrl+F5 无缓存刷新。<br />
> 额，这个快捷键在 FF 里是可以用的，其他浏览器小邪就不清楚咯。</p>
<p>> <a target="_blank" href="http://www.evlos.org/apps/demo/images_loading">http://www.evlos.org/apps/demo/images_loading</a></p>
<p><strong>2. 当然要先载入 jQuery 库：</strong></p>
<p>> 呵呵，这是为新来的童鞋提供的步骤，老童鞋就请直接跳过咯。<br />
> 貌似原来的 lastest.js 不见了，可能太多人载入这个文件，官方服务器挺不住。<br />
> 所以这个还是在 Google 服务器上托管的 JS 文件，请放心使用 O(∩_∩)O。</p>
<pre class="brush: jscript; auto-links: false; html-script: false; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
</pre>
<p><strong>3. 然后载入图片Loading提示的 jQuery 插件：</strong></p>
<pre class="brush: jscript; auto-links: false; html-script: false; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
(function($){
jQuery.fn.LoadImage=function(settings){
settings = jQuery.extend({ scaling : true,
width : 500,height : 500,loadpic:&quot;&quot; }, settings);
return this.each(function() {
$.fn.LoadImage.Showimg( $( this ), settings );
});};
$.fn.LoadImage.Showimg = function($this, settings){
var src=$this.attr(&quot;src&quot;);
var img=new Image();
img.src=src;
var autoScaling=function(){
if (settings.scaling) {
if (img.width &gt; 0 &amp;&amp; img.height &gt; 0) {
if (img.width / img.height &gt;= settings.width / settings.height) {
if (img.width &gt; settings.width) {
$this.width(settings.width);
$this.height((img.height * settings.width) / img.width);
}else {
$this.width(img.width);
$this.height(img.height);
}}else {
if (img.height &gt; settings.height) {
$this.height(settings.height);
$this.width((img.width * settings.height) / img.height);
}else {
$this.width(img.width);
$this.height(img.height);
}}}}}
$this.attr(&quot;src&quot;,&quot;&quot;);
var loading=$(&quot;&lt;img alt=\&quot;加载中...\&quot; title=\&quot;图片加载中...\&quot; src=\&quot;&quot;
+settings.loadpic+&quot;\&quot; /&gt;&quot;);
$this.hide();
$this.after(loading);
$(img).load(function(){
autoScaling();
loading.remove();
$this.attr(&quot;src&quot;,this.src);
$this.show();
});}})(jQuery);
&lt;/script&gt;
</pre>
<p><strong>4. 设置此 jQuery 插件的参数：</strong></p>
<p>> Loadpic 是设置提示图片的路径，宽度高度就不用管它了。<br />
> 这个宽度高度是图片最大高和图片最大宽，按比例缩放的，不过我们用不到。</p>
<pre class="brush: jscript; auto-links: false; html-script: false; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
$(function(){
	$(&quot;img&quot;).LoadImage({scaling : true,
			width : 3000,
			height : 3000,
			loadpic:&quot;imgload.gif&quot;});
});
&lt;/script&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rainmoe.com/2009/12/27/images-loading/feed/</wfw:commentRss>
		<slash:comments>53</slash:comments>
		</item>
		<item>
		<title>制作好一个输出Alex排名图片的API</title>
		<link>http://www.rainmoe.com/2009/12/14/made-a-api-can-output-alex-image/</link>
		<comments>http://www.rainmoe.com/2009/12/14/made-a-api-can-output-alex-image/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 07:50:07 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[作品 [Work]]]></category>
		<category><![CDATA[alex]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1589</guid>
		<description><![CDATA[> 嘿嘿，这个应该没有其他的人做了吧，独家喔。小邪昨天一直在做这个呢，O(∩_∩)O。

> 很方便的调用，说明在图片上，Type=2 则是提供此网站在其所属国家的排名。



<span class="readmore"><a href="http://www.rainmoe.com/2009/12/14/made-a-api-can-output-alex-image/" title="制作好一个输出Alex排名图片的API">阅读全文——共2587字</a></span>]]></description>
			<content:encoded><![CDATA[<p>> 嘿嘿，这个应该没有其他的人做了吧，独家喔。小邪昨天一直在做这个呢，O(∩_∩)O。<br />
> 很方便的调用，说明在图片上，Type=2 则是提供此网站在其所属国家的排名。</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/Capture0785.jpg" /></p>
<p>> 记得要加 Url= 喔，不必使用 Http 开头的地址。只支持 6 位数排名，超过则显示无限。<br />
> 正在制作缓存机制，尚未完成喔，缓存时间定为 3 天，这样就不必每次都到官方获取数据咯。</p>
<p><span id="more-1589"></span>> 预览传送门：<a target="_blank" href="http://tool.evlos.org/aleximg/">http://tool.evlos.org/aleximg/</a></p>
<p>1. <strong>PHP 中的字符串与数字</strong>：</p>
<p>> 在 PHP 里，字符串和数字之间是无需转换的，因为它会自动完成这个操作。<br />
> ╮(╯▽╰)╭，我感觉我解脱了，以前在 Delphi 里为了个类型转换就要纠结死，差点就升天了。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
&lt;?php
$j = &quot;10&quot;;
for ($i=1; $i&lt;=$j; $i++) {
 echo $i;
}
?&gt;
</pre>
<p>> 像在 For 循环里，$i 是数字，%j 是字符串，这里就可以直接用啦。<br />
> 因为加好是针对数值的，点才是针对字符串的。数值上来说 'aass' = 0。<br />
> 所以下面输出的 $i 和 $j 的计算结果都是 1。而 $k 和 $l 都是 1112。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
&lt;?php
$i = 'aass'+'1';
$j = 'aass'+1;
$k = '1111'+1;
$l = '1111'+'1';
echo $i.' '.$j.' '.$k.' '.$l;
?&gt;
</pre>
<p>2. <strong>Url 地址传递参数</strong>：</p>
<p>> 这是一个很方便的功能，不需要表单来引导，但请勿用来传递密码喔。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
http://tool.evlos.org/aleximg/get.php?url=verycd.com&amp;type=2
</pre>
<p>> 这里我就可以使用 $_GET['type'] 来获得需要的参数。<br />
> 记得使用 isset 函数判断参数是否存在喔，不进行判断的话会运行出错的</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
if(isset($_GET['type'])) {
	$output_type = $_GET['type'];
}
else {
	$output_type = null;
}
</pre>
<p>3. <strong>Strip_tags 函数</strong>：</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/Capture0783.jpg" /></p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$info = '&lt;p&gt;test&lt;/p&gt;';
$nop = strip_tags($info,'&lt;p&gt;');
</pre>
<p>> 这个函数去除 HTML 标签的能力很强悍的说，这样就直接变成了 'test' 啦，O(∩_∩)O。</p>
<p>4. <strong>对中文字符串的支持</strong>：</p>
<p>> 这个支持灰常好，可以像下面的代码一样直接用呢 (^o^)。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
if ($global_num == '无数据'||strlen($global_num)&gt;6) {
	$pic=&quot;img/global_unlimited.gif&quot;;
	$content = file_get_contents($pic);
	header(&quot;Content-Type: image/jpeg; charset=UTF-8&quot;);
	echo $content;
}
else {
	$pic_num = '';
	output_pic($global_num,$output_type);
}
</pre>
<p>> 第一次写了 167 行的代码，嘿嘿，记录一下。</p>
<p>5. <strong>使用  PHP 合并数字图片</strong>：</p>
<p>> 呵呵，当时为了自己好理解，而且数量不多，所以在这里就没有使用循环和数组咯。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
if ($num_cut[0] == null) {$source_img1 = imagecreatefromgif('img/num_emp.gif');}
else {$source_img1 = imagecreatefromgif('img/num_'.$num_cut[0].'.gif');}
if ($num_cut[1] == null) { $source_img2 = imagecreatefromgif('img/num_emp.gif'); }
else { $source_img2 = imagecreatefromgif('img/num_'.$num_cut[1].'.gif'); }
if ($num_cut[2] == null) { $source_img3 = imagecreatefromgif('img/num_emp.gif'); }
else { $source_img3 = imagecreatefromgif('img/num_'.$num_cut[2].'.gif'); }
if ($num_cut[3] == null) { $source_img4 = imagecreatefromgif('img/num_emp.gif'); }
else { $source_img4 = imagecreatefromgif('img/num_'.$num_cut[3].'.gif'); }
if ($num_cut[4] == null) { $source_img5 = imagecreatefromgif('img/num_emp.gif'); }
else { $source_img5 = imagecreatefromgif('img/num_'.$num_cut[4].'.gif'); }
if ($num_cut[5] == null) { $source_img6 = imagecreatefromgif('img/num_emp.gif'); }
else { $source_img6 = imagecreatefromgif('img/num_'.$num_cut[5].'.gif'); }
</pre>
<p>6 .<strong>请注意一下</strong>：</p>
<p>> 如果有哪个童鞋打算长期使用，请一定要和我说一声。<br />
> 有出现某些不得不做改动的情况的话，我会立即通知你做修改的。<br />
> 还有使用了我的 PR 调用的童鞋也麻烦吱我一声，谢谢支持。</p>
<p>7. <strong>欢迎来 Follow 我的 Twitter <a target="_blank" rel="nofollow" href="http://twitter.com/angelsolo">@AngelSolo</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rainmoe.com/2009/12/14/made-a-api-can-output-alex-image/feed/</wfw:commentRss>
		<slash:comments>65</slash:comments>
		</item>
		<item>
		<title>如何使用PHP来合并图片</title>
		<link>http://www.rainmoe.com/2009/12/13/merge-images-by-php/</link>
		<comments>http://www.rainmoe.com/2009/12/13/merge-images-by-php/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 10:34:31 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[代码 [Code]]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[merge]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1591</guid>
		<description><![CDATA[> 最近小邪玩了一下PHP，很不错，代码的可读性很高，如果有兴趣学习其实也不是很难的。

> 话说上次做了一个直接提供PR图片的API，蛮不错的，但是看 Webmasterhome 已经有了。



<span class="readmore"><a href="http://www.rainmoe.com/2009/12/13/merge-images-by-php/" title="如何使用PHP来合并图片">阅读全文——共1947字</a></span>]]></description>
			<content:encoded><![CDATA[<p>> 最近小邪玩了一下PHP，很不错，代码的可读性很高，如果有兴趣学习其实也不是很难的。<br />
> 话说上次做了一个<a target="_blank" href="http://www.evlos.org/2009/12/09/made-a-api-can-output-pr-image/">直接提供PR图片的API</a>，蛮不错的，但是看 Webmasterhome 已经有了。</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/snouuuu-1.jpg" /></p>
<p>> 还以为白做了呢，不过发现那个貌似没用掉了，怎么样都不肯显示，所以，嘿嘿嘿嘿。<br />
> 这次打算做另外一个API，需要用到图片合并功能，O(∩_∩)O，先保密，下篇文章揭晓喔。</p>
<p><span id="more-1591"></span>1. <strong>Image 图像函数说明</strong>：</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/Capture0768.jpg" /></p>
<p>2. <strong>Image 图像函数所支持的图像格式</strong>：</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/Capture0769.jpg" /></p>
<p>3. <strong>合并图像所需函数</strong>：</p>
<p>> Getimagesize - 取得图像大小<br />
> Imagecreatefromgif - 从 GIF 文件或 URL 新建一图像<br />
> Imagecreatefromjpeg - 从 JPEG 文件或 URL 新建一图像<br />
> Imagecreatefrompng - 从 PNG 文件或 URL 新建一图像</p>
<p>> Imgcopy - 拷贝图像的一部分</p>
<p>> Imagegif - 以 GIF 格式将图像输出到浏览器或文件<br />
> Imagejpeg - 以 JPEG 格式将图像输出到浏览器或文件<br />
> Imagepng - 以 PNG 格式将图像输出到浏览器或文件</p>
<p>4. <strong>Imgcopy 函数详解</strong>：</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/Capture0770.jpg" /></p>
<p>5. <strong>PHP header() 函数详解</strong>：</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/Capture0771.jpg" /></p>
<p>6. <strong>首先要将图片载入字符串中</strong>：</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/snow1.jpg" /></p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$source = '1.png';
$source1 = '2.png';
$target = 'emp.png';

$source_img = imagecreatefrompng($source);
$source_img1 = imagecreatefrompng($source1);
$target_img = imagecreatefrompng($target);
</pre>
<p>> 首先定义图像的地址为变量以作为 Imagecreatefrompng 函数的参数。<br />
> 当然直接把地址填到函数里也行的，我这样做是我博客页面宽度不够嘛，呵呵。<br />
> 记得直接填写的时候要加上俩个引号在两边喔，我个人比较喜欢单引号，忌混用。</p>
<p>> 当然 Imagecreatefromgif 和 Imagecreatefrompng 也是可以用的喔。<br />
> 这就要看你要处理哪种格式的图像咯，风景方面我比较看中画质，所以用 PNG。</p>
<p>> Emp.Png 是一张完全空白的图片，大小为两个来源图之和，为我们合并其他图像做准备。<br />
> 当然也可以不用，用函数创建一个，但是从学习角度来说，这样子应该容易理解一点。<br />
> 然后 1.Png 2.Png 两个文件是要被合并的图片。</p>
<p>7. <strong>开始横向合并图像</strong>：</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$size = getimagesize($source);
$size1 = getimagesize($source1);

imagecopy ($target_img,$source_img,0,0,0,0,$size[0],$size[1]);
imagecopy ($target_img,$source_img1,$size[0],0,0,0,$size1[0],$size1[1]);
</pre>
<p>> 用 Getimagesize 函数获得图像的尺寸，产生的是一个数组，$size[0]是宽，$size[1]是高。<br />
> 我们把 Source_img 放到 Target_img 的左上角，坐标为 0：0 的位置。<br />
> 然后把 Source_img1 放到 Target_img 中 Source_img 的右边。<br />
> 所以横坐标为 Source_img 的宽度。</p>
<p>8. <strong>生成或者打印图像</strong>：</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/ssss-1.jpg" /></p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
Header(&quot;Content-type: image/png&quot;);
imagepng($target_img);
</pre>
<p>> 在这里说的打印当然不是用打印机咯，呵呵，是显示在你的屏幕上。<br />
> 先使用 Header 函数向客户端发送原始的 HTTP 报头，告诉他你这个图片是PNG格式。<br />
> 然后使用 imagepng 输出即可，就会显示在屏幕上咯，可以右键另存为来着，嘿嘿。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
imagepng($target_img,'3.png');
</pre>
<p>> 当然也可以保存为文件呢，这样就好咯，相对路径也没问题的喔。</p>
<p>> O(∩_∩)O，其实写博有利于学习，你要让别人听懂，自己就一定要弄透彻，才能讲解出来。</p>
<p>9. <strong>欢迎来 Follow 我的 Twitter <a target="_blank" rel="nofollow" href="http://twitter.com/angelsolo">@AngelSolo</a></strong> 。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rainmoe.com/2009/12/13/merge-images-by-php/feed/</wfw:commentRss>
		<slash:comments>58</slash:comments>
		</item>
		<item>
		<title>制作好一个输出PR图片的API</title>
		<link>http://www.rainmoe.com/2009/12/09/made-a-api-can-output-pr-image/</link>
		<comments>http://www.rainmoe.com/2009/12/09/made-a-api-can-output-pr-image/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 06:35:07 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[作品 [Work]]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[pr]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1490</guid>
		<description><![CDATA[> ╮(╯▽╰)╭ 昨天白夜三更写的，糊涂地忘记了已经有蛮多网站提供这个功能了，结果就杯具了。

> 不过也没什么，这篇文章刚刚好总结一下 Curl 函数和 File_get_contents 函数的用法。



<span class="readmore"><a href="http://www.rainmoe.com/2009/12/09/made-a-api-can-output-pr-image/" title="制作好一个输出PR图片的API">阅读全文——共2672字</a></span>]]></description>
			<content:encoded><![CDATA[<p>> ╮(╯▽╰)╭ 昨天白夜三更写的，糊涂地忘记了已经有蛮多网站提供这个功能了，结果就杯具了。<br />
> 不过也没什么，这篇文章刚刚好总结一下 Curl 函数和 File_get_contents 函数的用法。</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/Capture0704.jpg" /></p>
<p>> 好多服务器为了防采集都禁止 File_get_contents，所以介绍一下俩函数互相替代的方法。<br />
> 话说，昨天给 619 的模板导航栏上加上了分类目录的显示，但我觉得那个模板的函数有点奇怪。</p>
<p>P.s. 呵呵，使用方法如图，作为图片显示即可，有兴趣的童鞋可以调用过去玩玩 O(∩_∩)O。</p>
<p><span id="more-1490"></span>1. <strong>File_get_contents 函数</strong>：</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/Capture0703.jpg" /></p>
<p>> 使用如下的代码可以将变量 $GontenPRURL 里的路径指向的文件读入字符串 $filecontent 中。<br />
> 只要在 Url 中传递参数即可到 Google 获取到 PR 的数值，然后转换为相对的图片文件名称。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$filecontent = file_get_contents($prurl);
</pre>
<p>> 我简单的使用下面的函数代码过滤了一下 Url 地址。<br />
> 因为没法过滤引号，所以后面再使用 Preg_match 的正则式过滤文件头。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$evlos_re = array(&quot;\&quot;&quot;,&quot;'&quot;,&quot;!&quot;,&quot;@&quot;,&quot;#&quot;,&quot;$&quot;,&quot;%&quot;,&quot;^&quot;,&quot;&amp;&quot;,&quot;*&quot;,&quot;(&quot;,&quot;)&quot;,&quot;+&quot;,&quot;=&quot;);
$website = str_replace($evlos_re,&quot;&quot;,$website);
</pre>
<p>> 最后再输出一个文件头，再把作为字符串的图片接着输出即可。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
header(&quot;Content-Type: image/jpeg; charset=UTF-8&quot;);
echo $content;
</pre>
<p>2. <strong>Curl 函数</strong>：</p>
<p>> <strong>注意！！</strong>CURLOPT_URL 参数是不支持相对路径的，网上没看到有人提到，害我差点没折腾挂掉。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$ch1 = curl_init();
$timeout1 = 15;
curl_setopt ($ch1, CURLOPT_URL, $prurl);
curl_setopt ($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch1, CURLOPT_CONNECTTIMEOUT, $timeout1);
$filecontent = curl_exec($ch1);
curl_close($ch1);
</pre>
<p>> 这里就得用那么长的代码来代替上面 File_get_contents 函数的那一行代码了。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$fixurl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$fixurl = str_replace(basename($_SERVER['PHP_SELF']),&quot;&quot;,$fixurl);
$pic = $fixurl.$pic;
</pre>
<p>> $pic 是我的 PR 图片文件，这里通过上面代码把相对路径转换为 Url 路径。<br />
> 最后也差不多，输出一个文件头，再把作为字符串的图片接着输出即可。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$ch2 = curl_init();
$timeout2 = 15;
curl_setopt ($ch2, CURLOPT_URL, $pic);
curl_setopt ($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch2, CURLOPT_CONNECTTIMEOUT, $timeout2);
$content = curl_exec($ch2);
curl_close($ch2);
</pre>
<p>3. <strong>同行输出日志分类与博客页面列表</strong>：</p>
<p>> 话说原先 Sandbox 只输出博客页面列表的时候 Header.php 只调用了一个函数：</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
&lt;?php sandbox_globalnav() ?&gt;
</pre>
<p>> 然后在主题函数 Functions.php 里面加了一大段这个代码：</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
function sandbox_globalnav() {
	if ( $menu = str_replace( array( &quot;\r&quot;, &quot;\n&quot;, &quot;\t&quot; ), '',
wp_list_pages('title_li=&amp;sort_column=menu_order&amp;echo=0') ) )
		$menu = '&lt;ul&gt;' . $menu . '&lt;/ul&gt;';
	$menu = '&lt;div id=&quot;menu&quot;&gt;' . $menu . &quot;&lt;/div&gt;\n&quot;;
	echo apply_filters( 'globalnav_menu', $menu );
}
</pre>
<p>> 我觉得其实没啥必要的样子，因为下面使用 WP 自带的函数输出一个 Li 列表也是可以达到相同效果的。<br />
> 博客页面是 Wp_list_pages，文章分类是 Wp_list_categories。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
&lt;div id=&quot;menu&quot;&gt;
&lt;?php wp_list_categories('title_li=0&amp;orderby=name&amp;show_count=0');
wp_list_pages('title_li=0&amp;sort_column=menu_order'); ?&gt;
&lt;/div&gt;
</pre>
<p>> 然后在 CSS 文件里面把 Li 变成行内元素即可，话说 Li 真是一个神奇的东西。</p>
<pre class="brush: css; auto-links: false; html-script: false; title: ; notranslate">
#access li {
display:inline;
padding-left:8px;
}
</pre>
<p>4. <strong>调用说明页面传送门</strong>：</p>
<p>> <a target="_blank" href="http://tool.evlos.org/primg/">http://tool.evlos.org/primg/</a></p>
<p>5. <strong>欢迎来 Follow 我的 Twitter <a target="_blank" rel="nofollow" href="http://twitter.com/angelsolo">@AngelSolo</a></strong> 。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rainmoe.com/2009/12/09/made-a-api-can-output-pr-image/feed/</wfw:commentRss>
		<slash:comments>71</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached (Feed is rejected)
Page Caching using memcached
Database Caching 1/21 queries in 0.090 seconds using memcached
Object Caching 432/476 objects using memcached

Served from: www.rainmoe.com @ 2012-02-09 16:53:21 -->
