Creating Image thumbnail forcely with PHP using Linux

If you are using a Linux based server and your PHP script is allowed to use exec() function of Linux. (I am writing this because due to security reason a lot of servers don’t allow this function to use from PHP script.)

 

If these are the criteria are full filled then below are one line PHP script that will resize your image to create thumbnail of the main image for any of your project based jobs. Exec function of PHP used to execute a external Program (mainly linux commands)

 

<?php

// this will create new thumbnail image 25% of original image here //home/admin/Desktop/gallery1.jpg is the path of main image and home/admin/Desktop/gallery1_new.jpg

 

//below function will use php/httpd to execute the task

 

exec('convert -resize 25% /home/admin/Desktop/gallery1.jpg /home/admin/Desktop/gallery_new.jpg');

?>

 

Force create Image thumbnail of specified height and width in PHP with one line script

 

<?php

// this will create new thumbnail image 25% of original image here //home/admin/Desktop/gallery1.jpg is the path of main image and home/admin/Desktop/gallery1_new.jpg

 

// here 100X100 is the width X height of image thumbnail

 

//below function will use php/httpd to execute the task

 

exec('convert -resize 100X100 /home/admin/Desktop/gallery1.jpg /home/admin/Desktop/gallery_new.jpg');

?>

 

Related posts:

The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video... Read More about Chandra Shekhar

Latest posts by Chandra Shekhar (see all)