<?php

$ext = array('jpg', 'jpeg', 'png', 'gif');

// pick up variables
if (isset($params['file']))
{
    // uploaded file object
    $file = $params['file'];

    // check file type
    if (in_array(strtolower($file->extension), $ext))
    {
        // get image width/height
        $contents = $file->download(false);

        // load into memory
        $im = imagecreatefromstring($contents);
        if ($im)
        {
            // get image size
            $imageWidth  = imagesx($im);
            $imageHeight = imagesy($im);

            // store width/height
            $dbInsert          = new DBObject("plugin_imageviewer_meta", array("file_id", "width", "height"));
            $dbInsert->file_id = $file->id;
            $dbInsert->width   = $imageWidth;
            $dbInsert->height  = $imageHeight;
            $dbInsert->insert();
        }
    }
}