图片尺寸什么的一直很烦人,太大?太小?占带宽?七牛有一个缩略图的API,不过可惜的是那个缩略图API只能在七牛的文件使用,变大变小都不能随心所欲!那么怎么办呢?机智的小幻有想弄了一个修改尺寸的API,直接弄进去,然后输出好了的尺寸不就OK了?
当然,这个API各种伪静态未作,如果你有兴趣,可以修改下,用这个生成修改尺寸的图片,然后由七牛缓存,这一切都是可以实现的,不过对于我这样的渣渣来说,伪静态,不会啊!
php修改图片尺寸API源码:
<?php
// The file
if($_GET["url"]){
$filename=$_GET["url"];
// Set a maximum height and width
if($_GET["w"]){
$width=$_GET["w"];
}else{
$width="2156";
}
if($_GET["h"]){
$width=$_GET["h"];
}else{
$height="2156";
}
// Content type
header('Content-Type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, null, 100);
}else{
header('Content-Type: text/html; charset=utf-8');
echo'<meta http-equiv="refresh" content="3;url=http://tu.ihuan.me">';
echo"您输入的参数有误,请重新输入———小幻美图(tu.ihuan.me)";
}
?>
是按照比例进行修改的,欢迎各位大神挑刺!
好了,当然我这里也有API的
图片尺寸修改API地址:http://tu.ihuan.me/api/image.php?url=http://xxx.xxx&w=xxx&h=xxx
其中url=后参数必须填写,其他可不填写,填写w或h其中一项则按照其中的参数成比例修改尺寸
示例:http://tu.ihuan.me/api/image.php?url=http://s.cn.bing.net/az /hprichbg/rb/PetrifiedForestNP_ZH-CN10820635777_1366x768.jpg&w=500
但是,我这里不能进行缓存,如果自己想要,可以把上面的文件弄下来,然后自己修改下,存到七牛里(真是太机智了!)
如果有写好了的伪静态规则,给我份吧!我是真的不会写,简单的还行,可是这个不简单。
好了,就这些了,欢迎大家食用,流量大的还是用自己的空间来执行吧,小站受不了!
最后打个AD:欢迎大家食用本站的随机图片等API,已经有100张图了,配合一下上面的API食用更美味!
You ought to take part in a contest for one of the greatest sites on the internet.
2018年8月19日 20:32I am going to recommend this site!
Hi, I want to subscribe for this website to get hottest updates,
2018年8月19日 20:24thus where can i do it please help out.
When some one searches for his necessary thing, thus he/she wishes to be available that in detail, thus that thing is
2018年8月19日 20:11maintained over here.
Actually no matter if someone doesn’t understand then its up to other viewers that they will help, so
2018年8月19日 20:01here it takes place.
Great post. I was checking continuously this blog and I am impressed!
2018年8月19日 19:57Extremely helpful information specially the remaining section :) I take care
of such info a lot. I used to be looking for this particular information for a long
time. Thanks and best of luck.
hello!,I really like your writing very a lot! share we keep up a correspondence extra approximately your article on AOL?
2018年8月19日 19:39I need a specialist in this space to solve my problem.
Maybe that’s you! Looking ahead to see you.
Hello! Do you know if they make any plugins to assist with SEO?
2018年8月19日 19:26I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains.
If you know of any please share. Thank you!
These are genuinely great ideas in regarding blogging.
2018年8月19日 19:10You have touched some pleasant factors here. Any way keep up
wrinting.
I’ve been surfing online more than 3 hours today, yet I never found any interesting article like yours.
2018年8月19日 19:08It’s pretty worth enough for me. In my opinion, if all site owners and bloggers made good content as you did,
the internet will be a lot more useful than ever before.
Thanks for another informative website. Where else
2018年8月19日 18:57may I am getting that kind of information written in such an ideal way?
I’ve a mission that I’m simply now working on, and I’ve been at the glance out for such information.