2009
Using PHP and ImageMagick to resize images

Today, I had to write some code to generate thumbnails in PHP. The php-gd library wasn’t installed and I had to work with ImageMagick. Not the most elegant of solutions, but it works:
1 2 3 4 5 6 7 8 9 10 11 | define('PRAVIN_THUMBNAIL_DIR', '/home/firedev/public_html/wp-content/cache/thumbnails/'); function pravin_resize($img_path, $width, $height) { $resolution = '"' . $width . 'x' . $height . '"'; $output_path = PRAVIN_THUMBNAIL_DIR . md5($img_path) . "-$resolution.jpg"; // If file does not exist OR the thumbnail was generated more than // 5 mins (5 x 60 sec) then re-create the thumbnail if(!file_exists($output_path) || (time() - filemtime($output_path)) > (5 * 60)) { system("/usr/bin/convert -resize $resolution $img_path $output_path"); } return $output_path; } |



How do I generate thumbnails with PHP using ImageMagick? - QuestionBin - Intelligent Answers for Smart Questions::Answer
[...] Paratey has a blog post on the [...]