rss
logo

I provide consulting and custom development for Natural Language Processing, Information Extraction and Search solutions.Self Picture


 learn more   get in touch 

Logo - I Build Search
Sep 09
2009

Using PHP and ImageMagick to resize images digg

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:

functions.php
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;
}

One Response (rss) (trackback)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Latest Articles

Apr
07

Palindromic sub-sequences in python

This bit of python code returns all palindromic subsequences in the input string.

[Read More]
Feb
19

Join a list of integers in Python

How do you run a string join on a list of integers in Python? After googling for about 10 mins, I gave up and did this. I am sure there is a better way of doing it!

[Read More]

Featured Projects

Indic to English Transliterator

Indic to English Transliterator

Transliteration is the process of converting a word from one language to another while retaining its phonetic characteristics. This application lets you convert a word from any major Indian language (currently supports Hindi, Marathi, Sanskrit and Bengali) to English.

[Read More]

Deebot

Deebot

Deeb0t is an IRC chat bot capable of making meaningful conversation with other users. It also responds to commands issued by its owner.

[Read More]

This page and its contents are copyright © 2010, Pravin Paratey.