在php jpg / png / gif中动态缩放图像 [英] dynamically scale images in php jpg/png/gif

查看:207
本文介绍了在php jpg / png / gif中动态缩放图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种在php中动态缩放图像的简单方法?

Is there a simple way of dynamically scaling an image in php?

我想特别使用某种功能,我可以将它插入到我的heml中,例如

Id like to specifically use some kind of function where i can insert it into my heml such as

<img src=image.php?img=boss.jpg&width=500>

然后它会将图像缩放到任何高度,将其限制为500px宽

and of course it would then scale the image to whatever height constrains it to 500px wide

我感谢所有输入,谢谢。

i appreciate all input, thanks.

编辑确实需要包含jpg png和gif文件类型

EDIT does need to include jpg png and gif file types

推荐答案

我更喜欢 WideImage 库,因为它真的很容易使用。

I prefer WideImage library, because it's really really easy to use.

在你的情况下,你需要做的就是:

In your case, everything you have to do is:

$img_path = $_GET['img'];
$new_width = $_GET['width'];

$new_img = wiImage::load($img_path)->resize($new_width);

header('Content-Type: image/jpeg');

echo $new_img->asString('jpg', 80);

它支持jpeg,png,gif,gd,...

And it supports jpeg, png, gif, gd, ...

这篇关于在php jpg / png / gif中动态缩放图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆