THESE CODES ARE PROVIDED FOR AN EXAMPLE OF HOW TO USE IMAGEMAGICK WITH PHP. CARE SHOULD BE TAKEN WHEN ACCEPTING USER INPUT.
I TAKE NO RESPONSABILTY FOR ANY PROBLEMS THAT MAY OCCURE WHEN USING ANY OF THIS CODE.
IT IS UP TO YOU TO SECURE THE CODE AND VALIDATE USER INPUT.
This example reads a directory and creats thumbnails of all the images. It can be modified to only read certain files, the files can or can not be overwriten, the filenames can be changed and the ImageMagick code can be modified to add watermarks etc.
The file names will be the same type as the original with a thumb_ prefix
// Setup the maximium width and height for the finished image $max_width = '200'; $max_height = '90'; // Directory containing the images $dir = 'photos'; // Select all jpg, png and gif images foreach (glob($dir."{*.jpg,*.png,*.gif}",GLOB_BRACE ) as $filename) { // Get the image size for use in the code $size=GetImageSize( $filename ); $new_name = 'thumb_'.$filename; $cmd = " $filename -thumbnail $max_widthx$max_height "; exec("convert $cmd $new_name"); }