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');
?>
Chandra Shekhar
Latest posts by Chandra Shekhar (see all)
- Best practices for micro service design - January 23, 2022
- Spring Boot - January 23, 2022
- Java - January 23, 2022
Recent Comments