


$nimg = imagecreatetruecolor ( $n_width, $n_height ) $img = imagecreatefromjpeg ( $orginal_filename ) Set the height and width of the new image After executing the following script, the original image and the cropped images will be shown in the browser. This function takes ten argument values to resize the image and it returns true for resizing the image successfully, otherwise returns false. The modified image shows the cropped image based on the values used imagecrop() function.Įxample-2: Resize image using imagecopyresized() functionĬreate a PHP file with the following script to resize the image by using imagecopyresize() function. The following output will appear after executing the above script. Imagejpeg ( $img_crop, $modified_filename ) Crop the image based on the argument used in imagecrop() function
Php image resize install#
Run the following commands to update the system and install the gd library of PHP. You have to install this library and enable the gd extension in the php.ini file before testing the script of this tutorial.ġ. The GD library of PHP has been used in this tutorial to load and resize the image.

PHP has many types of built-in functions to resize an image and any of them can be used based on the returned value of the getimagesize() function. The first three indexes are mainly required to resize the image and these indexes contain the width, height, and type of the image. The getimagesize() function is used to retrieve the necessary information of any image that will be used to resize the image.
