Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

dynamically scale images in php jpg/png/gif

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

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>

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

i appreciate all input, thanks.

EDIT does need to include jpg png and gif file types

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...