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');

?>

 

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 Conferencing and social media domain. The motive of creating cutehits was just to share the knowledge/solutions I get to know during my day to day life so that if possible I can help someone for same problems/solutions. CuteHits.com is a really a very effort for sharing knowledge to rest of the world. For any query/suggestion about same you can contact me on below details:- Email: shekharmca2005 at gmail.com Phone: +91-9560201363

Latest posts by Chandra Shekhar (see all)

You may also like...