Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

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, ...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...