Sometimes, we want to resize image in PHP.
In this article, we’ll look at how to resize image in PHP.
How to resize image in PHP?
To resize image in PHP, we can use GD.
To use it, we write
$image_name = "path_of_Image/Name_of_Image.jpg";
$image = imagecreatefromjpeg($image_name);
$imgResized = imagescale($image, 500, 400);
to call imagecreatefromjpeg
with the $image_name
path string.
Then we call imnagescale
with the $image
object returned by imagecreatefromjpeg
and the width and height that we want to resize the image to.
The resized image is returned by imagescale
.
We can also use imagecreatefrompng
to open png images and imagecreatefromgif
to open gifs.
Conclusion
To resize image in PHP, we can use GD.