Imagoxy: A Picasa Image Proxy for Personal Website and Blog
Picasa had been banned in Mainland China yesterday. I don't know if it is temporary or persistent. Lots of pictures on my blog are stored in Picasa. Unlike Flickr, I found it difficult to replace domain name or IP to pass the URL/IP filter. So I choose another way: download pictures from Picasa server to my Godaddy host, and replace the picture links in my posts from Picasa to my host. I wrote Imagoxy, a tiny PHP toolkit and Imagoxy-WP, a wordpress plug-in to implement this automatically and dynamically. This mechanism will certainly apply additional overhead and occupy more bandwidth. However, it is sustainable for my small website. Experiment shows it works well with wordpress 2.8.1. I make it open-source under a BSD license and you can get it from SourceForge or WordPress Plugin page.
Security issues should be considered carefully before it being used in significant applications. Some measures had been taken, but I hope you to review my codes and eliminate the hidden dangers. If you are interested in Imagoxy, welcome to join the small project at SourceForge and contribute your codes! Thanks.
I do not profit from my open source works. But if you really think they are useful, you can click here.
Imagoxy Version 0.53 - Update: 2009/12/10
Imagoxy-WP Version 0.53 - Update: 2009/12/10
Imagoxy
Imagoxy ("image proxy") is a tiny PHP toolkit. It downloads pictures from remote server to local server and relocate corresponding http requests to the local one. It is used to access pictures when the remote server is banned or slow from the network of clients (e.g. Download pictures from Picasa on an unbanned US server and tranfer them to China's viewers where Picasa is banned sometimes).
Licensed under a BSD license.
Install:
1. Modify Imagoxy 'getimg.php' file:
* Set '$work_dir' to the location you wish Imagoxy works at.
* Set '$cache_dir' to the location you wish files downloaded to. (default is OK in most cases)
* Set '$error_file' as the file relocated to when access control denied. (default is OK in most cases)
* Set '$reffer_list' as the legal HTTP_REFERER prefix list.
* Set '$check_reffer_before_download' as whether to check HTTP_REFERER before downloading new picutre.
* Set '$check_reffer_before_show' as whether to check HTTP_REFERER before showing downloaded picutre.
* Set '$legal_pattern' as the legal file URL patterns. (default is for Picasa; you can add more)
2. Update the 'imagoxy' directory to your '$work_dir' and make the '$cache_dir' writable.
3. Configure and deploy Imagoxy front-ends such as Imagoxy-WP.Usage:
1. [ http://www.example.com/imagoxy/getimg.php?s={original URL} ] In this format (we called 'Imagoxy URL'), the http request will be relocated to a file on local server which is downloaded from the original URL. You can embed the Imagoxy URL into your <img src="..."> label. 'http://' in original URL is omissible and the other protocols are not allowed. Notice: as a parameter, original URL should be url-encoded again even if it has been url-encoded. e.g. 'Pic%20A.jpg' -> 'Pic%2520A.jpg'.
2. [ http://www.example.com/imagoxy/getimg.php?u={encoded URL} ] Also does downloading and relocation. However, you should base64-encode, reverse and then url-encode the original URL. In PHP, these are done by 'urlencode(strrev(base64_encode($original_url)))'. This encoding method can pass the URL filter in certain regions.Test:
You can write a html page with an Imagoxy URL in <img src="..."> label. Open it locally, you should see the '$error_file'; after uploading it to the server with the URL prefix in '$reffer_list', you will see the relocated picture correctly.
Enjoy it!
Imagoxy-WP
Imagoxy-WP is a wordpress front-end for Imagoxy. Imagoxy downloads pictures from remote server to local server and relocate corresponding http requests to the local one. It is used to access pictures when the remote server is banned or slow from the network of clients. Imagoxy-WP now converts Picasa URLs to local Imagoxy URLs, and you can also add your customed conversion.
Licensed under a BSD license.
Install:
1. Download Imagoxy. Imagoxy is available at https://sourceforge.net/projects/imagoxy/.
2. Configure and deploy Imagoxy on your server as Imagoxy's README file described.
3. Modify Imagoxy-WP 'imagoxy-wp.php' file:
* Set '$imagoxy_dir' to your Imagoxy location, which is the same as '$work_dir' in Imagoxy.
4. Upload Imagoxy-WP php file or the whole directory to your wordpress '/wp-content/plugins' directory.
5. Enable it in the dashboard.After that, You will see:
<img src="http://lhX.ggpht.com/_WWW/XXX/YYY/ZZZ/sMMM/IMG_NNN.JPG" />
in your blog posts now becomes:
<img src="http://www.example.com/imagoxy/getimg.php?u=AABBCCDDEEFFGGHH" />
Since pictures are downloaded from your own server, it won't be banned then.Enjoy it!





22条评论 关于 “Imagoxy: A Picasa Image Proxy for Personal Website and Blog”
由 Kyle Cheng 发表于2009-07-18
oh. your english become very impressive.:)
由 lenin 发表于2009-07-18
Does this plugin download images from picasa and then store them in a temporary directory ? Will the storage be cleaned after a short while to save the space ?
由 Jian Lin 发表于2009-07-18
Yes. The downloaded pictures won't be deleted periodically.That is to say the same picture will be downloaded only once.
After all, it is an experimental tool for personal use. I have shown the feasibility and you can modify the PHP codes to cater to your particular needs.
由 Showfom 发表于2009-07-19
不错不错 特意跑过来支持 哈哈
由 许三品 发表于2009-07-19
为什么是英文?针对中国大陆不是应该以中文为主吗?
由 ljp 发表于2009-07-19
高人,能不能把所有图片打包,然后提供下载。最近正在学习CRF,觉得你写的东西很容易理解,但是就是缺这些图片,看得有点迷糊。感谢!
由 Jian Lin 发表于2009-07-19
@许三品 呵呵,写英文一是因为这东西发布在sf.net上,需要英文文档,我写完英文就懒得翻译成中文了,直接贴在blog上;二是因为这个插件也只能用在国外的服务器上,会用国外服务器的人也应该可以看懂英语。
由 Jian Lin 发表于2009-07-19
@ljp Sorry,我没明白你的意思,我没有提供什么图片呀?
由 beetea 发表于2009-07-20
不错,我已经加到我的帖子里了
由 悠游绿洲 发表于2009-07-20
Thanks very much for this great plugin. Now I've been so disappointed to the gov. I am one of the victims of this event. Now I decide to store all my images on my own shared server. Anyway, thanks for providing another way to solve the problem
由 najja 发表于2009-07-20
其它都很好,只是如果文件名中间有空格就没有办法显示,能不能把bf4a0d13093536966b57a62c934b7199-Picture%2010.png这种文件名的后半部分直接去掉呢?
由 najja 发表于2009-07-20
上面那个已经被我改好了汗,不过又发现另外一个问题,picasa官方引用方式之一是在图片后面加上?imgmax=800标注大小,比如http://lh4.ggpht.com/_EeYI5lWhd_s/SZ1TVWqdCLI/AAAAAAAAATI/-8PolRPDQss/Picture%207.png?imgmax=800,貌似这个plugin处理不了这样的,我基本不懂php实在改不了了
由 Jian Lin 发表于2009-07-20
@najja 谢谢关注。前一个问题是比较好解决,给url加一个urldecode就可以了。后一个问题,带query string的URL是我之前没有考虑的,我看看有没有好的解决方法。看来现在的版本在特殊字符处理上还有点问题,我会尽快修改并更新代码。
由 Jian Lin 发表于2009-07-20
@najja 已更新到0.51版本,解决了你的两个问题:
1. Support original URL with query string.
2. Support original URL with special characters.
由 zyboy3707 发表于2009-07-24
你们时间都很多。
由 ElenaLisvato 发表于2009-08-06
amazing stuff thanx
由 BYF 发表于2009-12-01
amazing!
由 老张 发表于2009-12-05
我想问下,图片是被下载回来了,但是文章中的图片链接地址还不是本地的呀,怎样能直接指回本图片的地址.
由 Jian Lin 发表于2009-12-05
@老张 在WordPress中安装并启用Imagoxy-WP插件应该就可以了,里面做了正则表达式替换。如果没有替换,可能是你使用了诸如缓存之类的插件,没有自动更新页面?如果没有缓存,那就看看自己的图片URL是否符合Imagoxy-WP的php文件中的正则表达式定义,不符合的话自己修改一下这个php。