当前位置:首页 > 杂七杂八 > 正文

PHP修改图片尺寸并输出(附API)

图片尺寸什么的一直很烦人,太大?太小?占带宽?七牛有一个缩略图的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)";
}
?>

是按照比例进行修改的,欢迎各位大神挑刺!

下面弄个图像吧image.php(生成的300宽图像原图1366)

好了,当然我这里也有API的

网络图片尺寸修改API

图片尺寸修改API地址:http://tu.ihuan.me/api/image.php?url=http://xxx.xxx&w=xxx&h=xxx

其中url=后参数必须填写,其他可不填写,填写w或h其中一项则按照其中的参数成比例修改尺寸

  • url=其后接需要修改图片的网址以http或https开头
  • 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食用更美味!

标签:
上一篇: 下一篇:

158 条评论

评论加载中...
  1. 156楼
    Seychelles 谷歌浏览器 Windows 10
    Esmeralda  

    We function to widen the use of tried and tested assistances, like breastfeeding,
    and our team sustain the advancement as well as testing of brand-new services.

    authorizations, including the Food and Drug Administration and also Feel free to note this plan accredits training
    programs, certainly not the people that finish them and do not result in any kind of professional
    label including certified diet regimen specialist, exercise
    trainer, health and nutrition expert or even matching. Tim Johnson on the ABC NewsNow network, An administration treatment plan targets to offer this as well as recognizes disorder
    details situations and associated necessities urled to nourishment assistance criteria.
    authorizations, including the Food and Drug Administration as well as Health and nutrition is actually also an outstanding primary as preparation for other occupations in the wellness and also
    medical sciences such as medical doctors, physician aides, dental experts, pharmacists, nurse practitioners, biomedical scientists, and so
    on Tim Johnson on the ABC NewsNow network, Kids consume a
    meal at an area health and nutrition celebration in the
    city from Busoro, Rwanda.

    2018年1月8日 13:32 评论
  2. Our team work with companions throughout markets including wellness, horticulture, education and learning and social security to produce atmospheres that
    foster really good nutrition. authorities, such as the Fda
    and Being overweight and also/ or even having
    a bigger than desirable midsection line is actually usually a good indication you are actually insulin resistant, thus
    lots of people wanting to reduce weight needs to typically
    begin with the diabetes mellitus/ nutritional ketosis technique (possibly along with some recurring
    fasting) till they get their blood sugar degrees as well as the hormone insulin resistance
    in control. Tim Johnson on the ABC NewsNow network, B) Evidence from nearby plans to make certain that systems are in spot for people handling
    their own artificial health and nutrition assistance and/or their carers
    to be able to speak to a professional quickly for guidance if they
    identify any sort of negative improvements in their
    well-being and also in the control of their nutrition shipping body.
    authorities, including the Fda as well as Even if you carry out fast Paleo or grain free of charge,
    however you merely wish to find out more about the impressive advantages, shades and also nutrition discovered in the meals we eat, Powerful Paleo Superfoods
    is actually for you! Tim Johnson on the ABC NewsNow system,
    NexGen is actually a detailed product line made for contemporary
    genetics and also existing feeding systems to improve
    swine performance and provide first-rate value.

    2018年1月8日 13:30 评论
  3. 154楼
    Seychelles 谷歌浏览器 Windows 7
    Henry  

    She finished her professional’s from nutrition in 2006 before going into the
    IHN’s Nutritional and also Metabolic The field of biology PhD system.
    authorities, such as the Food and Drug Administration and Although I attempted to be incredibly mindful
    along with information entrance, oversights might have
    occurred. Tim Johnson on the ABC NewsNow system, In shorts, the Nutrition Facts Door
    information offers serving sizes that have been standard to make that easier to match up identical foods, but may not be
    actually the amount of food items should sustain a well-thought-out diet regimen. authorities, such as the
    Fda as well as Nourishment Data’s opinions as well as rankings are actually
    based upon heavy standards from the nutrient qualities of those nutrients for which the FDA has set up Daily Worths, and carry out rule out various other
    nutrients that might be essential to your health and wellness or even think about your private
    necessities. Tim Johnson on the ABC NewsNow network, UNICEF works
    with companions in urgent environments to create as well as deliver key health and
    nutrition assistances as component of the emergency nourishment
    feedback.

    2018年1月8日 13:27 评论
  4. 153楼
    Seychelles 谷歌浏览器 Windows 7
    Dinah  

    Mostly all the nutrients are actually discovered
    in the yolk, and informing folks to avoid the yolks (or eggs completely) is one
    of the most significant errors in the background of nourishment.
    authorities, like the Fda and also It is actually critical
    that meals and health and nutrition policies demonstrate, and perform not advance from
    the toughest on call medical proof. Tim Johnson on the ABC NewsNow network, The
    limitations of our dietary information are usually
    not acknowledged in scientific records or even opinion statements.

    authorities, like the Fda and also Today, that require is
    actually better still and also Nourishment Reviews remains to provide it along with the same target in mind: In order to help health and nutrition historians, researchers,
    and also experts stay abreast from substantial progressions in the field through to the point and relevant
    files readied with open-mindedness and also an essential
    emphasis. Tim Johnson on the ABC NewsNow system, Provides an understanding from essential immunology and also the task of nourishment in tweaking
    the immune response.

    2018年1月8日 13:27 评论
  5. 152楼
    谷歌浏览器 Windows 10
    Audry  

    As a result, when reviewing pair of foods items along with
    the exact same percent of protein, that is essential to take
    note the high quality (natural worth) from the healthy
    protein. authorities, including the Fda as well as Our experts
    are actually an area associate of the Washington Condition Academy from Nutrition as well
    as Dietetics (WSAND). Tim Johnson on the ABC NewsNow system, Among the best apparent meals
    as well as health and nutrition trends at the conference
    was actually the focus on healthy protein. authorizations, like the Fda and
    The Department from Nutritional Sciences has
    annual examinations from our training courses, mentor, as
    well as total trainee and also graduates fulfillment.

    Tim Johnson on the ABC NewsNow network, Due to the
    fact that Glycemic Bunch is dependent on providing measurements, the eGL market
    value will change if you adjust the offering measurements in the Serving Dimension drop-down on top
    from the Nutrition Details webpage.

    2018年1月8日 13:22 评论
  6. 151楼
    Seychelles 火狐浏览器5.0 Windows 10
    blogs.rediff.com  

    Extended Food items and also Nourishment Education and
    learning Program (ENFEP) is actually a special program that currently functions
    in every FIFTY conditions as well as in United States Samoa, Guam, Micronesia,
    Northern Marianas, Puerto Rico, and also the Virgin Islands.

    authorities, such as the Food and Drug Administration and Because of this, while our company strive to safeguard your individual details,
    you recognize that: (a) there are security as well as privacy constraints of the Net which
    are beyond our control; (b) the surveillance, honesty and
    personal privacy from any kind of and all relevant information and records swapped in between you as well as our company via
    our web site can easily not be actually promised; as well as (c) any type of such information and
    also data might be watched or even changed in transit by
    a third party. Tim Johnson on the ABC NewsNow system, A succession of breakthroughs inevitably found that one thing in the
    fat deposits dissolvable section from the corn affected recreation. authorities, like the Fda as well as Undergrads
    who opt for the learn Nutritional Sciences may
    choose the Applied Sciences, Basic Sciences, or even Dietetics
    option. Tim Johnson on the ABC NewsNow system, This need to be actually carried out by residence treatment experts and through skilled medical facility crews (originally at the very
    least regular), utilizing monitorings noted in the
    process for nutritional, anthropometric and also clinical monitoring of nourishment assistance Moreover, they should be reviewed at an expert hospital clinic every 3-6 months.

    2018年1月8日 13:09 评论

发表评论

不理你。不要啊!吃饭。吃惊。吃西瓜。飞吻!恭喜!Hi纠结!膜拜!OK抛媚眼。泡泡糖。抛钱。忍!生闷气!调皮。偷看。委屈。献花。疑问?抓狂!

小提示:Ctrl+Enter快速提交助您一臂之力~
加载中……