图片尺寸什么的一直很烦人,太大?太小?占带宽?七牛有一个缩略图的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食用更美味!
Today, I went to the beach front with my children. I found a sea shell and gave it
2018年5月26日 00:41to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.”
She put the shell to her ear and screamed. There was a hermit crab inside and it
pinched her ear. She never wants to go back!
LoL I know this is entirely off topic but I had to tell someone!
Attractive component to content. I simply stumbled upon your
2018年5月26日 00:07blog and in accession capital to say that I acquire in fact enjoyed
account your blog posts. Any way I will be subscribing on your feeds
or even I fulfillment you get entry to consistently quickly.
I’m not sure where you are getting your info, but great topic.
I needs to spend some time learning more or understanding more.
Thanks for excellent information I was looking for this info for my
2018年5月25日 20:37mission.
It’s ɑctually ɑ nice and helpful piece of info. I’m hаppy that yⲟu shared thiѕ usеful іnformation ᴡith us.
2018年5月25日 19:45Please keep uѕ informed ⅼike thіs. Ꭲhanks for sharing.
When I initially commented I clicked the “Notify me when new comments are added” checkbox and
2018年5月25日 14:36now each time a comment is added I get several emails with the same comment.
Is there any way you can remove me from that service?
Many thanks!
I blog quite often and I truly appreciate your information. Your
2018年5月25日 12:41article has really peaked my interest. I’m going to bookmark your blog and keep
checking for new details about once a week. I subscribed to your RSS
feed as well.
Aw, this was an incredibly nice post. Spending some time
2018年5月25日 10:22and actual effort to generate a great article?
but what can I say? I put things off a lot and don’t manage
to get anything done.
You actually make it seem so easy with your presentation but I find this
2018年5月25日 04:58matter to be really something that I think I would never understand.
It seems too complicated and very broad for me. I am looking
forward for your next post, I will try to get the hang of it!
Pretty great post. I just stumbled upon your blog and wanted to mention that
2018年5月25日 03:09I have truly enjoyed browsing your weblog posts. After all I’ll be
subscribing in your rss feed and I’m hoping
you write once more very soon!
Howdy very nice website!! Man .. Excellent
2018年5月25日 01:27.. Amazing .. I’ll bookmark your website and take the feeds additionally?
I am satisfied to search out a lot of useful information here in the submit,
we need work out extra strategies on this regard,
thank you for sharing. . . . . .