Magic Mime Database Workaround

Timthumb is a very useful PHP script used heavily to resize images on the fly in many WordPress themes. Timthumb uses a PHP function FINFO_OPEN to get info regarding the image. The function FINFO_OPEN uses a magic.mime database, which is basically a text file, to get information regarding the type of image. Many hosts (like mine) do not provide the magic.mime extension and hence the script cannot resize the image on the fly. The magic.mime file if present is present at /usr/share/magic.mime. However, if the host does not provide it, there is a workaround to get the magic.mime file working with the Timthumb script.

The FINFO_OPEN function takes the path to the magic.mime file as a parameter. You could download the file and put it in the same directory as the Timthumb script and test out if the images are being resized. The code which needs to be changed should look like this :

$finfo = finfo_open(FILEINFO_MIME, "./magic.mime");

You could get the magic.mime file from any Apache installation. does not allow me to upload a .mime extension file or else I would have upload it here directly. Let me know if you need the magic.mime file.

2 thoughts on “Magic Mime Database Workaround

  1. Your post has been very helpful. Timthumb now looks for the magic database in the same folder it exists in, but the only magic file I was able to find in the Apache download is the documentation. I assume it’s because the database is generated upon compilation and installation of the Apache package. Would you be so kind as to email ‘magic.mime’ to me?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s