Home > Groups > PHP developers > resize image using php

resize image using php

Article
Published in

1) First Check GD library is enable or not

To check GD library print phpinfo using code <?php echo phpinfo(); ?> in any php file ( View snapshot  below )

GD Library

2) IF you did not find GD using your phpinfo, it mean GD library is not enable. For enabling GD go to php.ini file. If you don't know where are you php.ini file then go to phpinfo which we have printed in above step and get path of php.ini ( View Snapshot Below)

php.ini path

3) Open your php.ini file using any text editor find line ;extension=php_gd2.dll on Windows OR ;extension=gd.so on Linux

4)To enable GD Remove ";" from the front of extension in above line and save php.ini file and then restart apache server.

5) Now when you will open phpinfo again. it will show GD is available in extension list.

6) Now Start Coding of " Image Resizing"

7) Copy & Past Below code

<?php
header("Content-type:image/jpeg"); // Ouput image in jpeg format
$img = imagecreatefromjpeg("http://www.cssnz.org/flower.jpg"); // OR put your file in this function
$ImageInfo = getimagesize("http://www.cssnz.org/flower.jpg"); // Return image information array
$new_width = 200; // set width for image
$new_height = 200; // set height for image
$new_img = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($new_img, $img, 0, 0, 0, 0,$new_width,$new_height,$ImageInfo[0],$ImageInfo[1]);
imagejpeg($new_img);
?>

For more info about GD functions click here

Your rating: None

Bookmark and Share
Home Back To Top