function output()
 {
     global $CFG;
     $result = '<script type="text/javascript" src="' . $CFG->wwwroot . '/mod/lightboxgallery/js/prototype.js"></script>    
                 <script type="text/javascript" src="' . $CFG->wwwroot . '/mod/lightboxgallery/js/scriptaculous.js?load=builder,dragdrop"></script>
                 <script type="text/javascript" src="' . $CFG->wwwroot . '/mod/lightboxgallery/js/cropper.js"></script>
                 <script type="text/javascript" charset="utf-8">
                     function onEndCrop( coords, dimensions ) {
                         $( \'x1\' ).value = coords.x1;
                         $( \'y1\' ).value = coords.y1;
                         $( \'x2\' ).value = coords.x2;
                         $( \'y2\' ).value = coords.y2;
                         $( \'cropInfo\' ).innerHTML = \'' . get_string('from') . ': \' + coords.x1 + \'x\' + coords.y1 + \', ' . get_string('size') . ': \' + dimensions.width + \'x\' + dimensions.height;
                     }
                     Event.observe( 
                         window, 
                         \'load\', 
                         function() { 
                             new Cropper.Img( 
                                 \'cropImage\',
                                 {
                                     onEndCrop: onEndCrop 
                                 }
                             ) 
                         }
                     );
                 </script>';
     $result .= '<input type="hidden" name="x1" id="x1" value="0" />
                 <input type="hidden" name="y1" id="y1" value="0" />
                 <input type="hidden" name="x2" id="x2" value="0" />
                 <input type="hidden" name="y2" id="y2" value="0" />
                 <table>
                   <tr>
                     <td>' . lightboxgallery_make_img(lightboxgallery_get_image_url($this->gallery->id, $this->image), 'cropImage') . '</td>
                   </tr>
                   <tr>
                     <td><span id="cropInfo">&nbsp;</span></td>
                   </tr>
                   <tr>
                     <td><input type="submit" value="' . get_string('savechanges') . '" /></td>
                   </tr>
                 </table>';
     return $this->enclose_in_form($result, 'coord');
 }
function lightboxgallery_image_thumbnail($courseid, $gallery, $file, $offsetx = 0, $offsety = 0)
{
    global $CFG;
    // If anything fails when retrieving the thumbnail, we'll fallback to just printing a label
    $fallback = '[' . $file . ']';
    $oldpath = $CFG->dataroot . '/' . $courseid . '/' . $gallery->folder . '/' . $file;
    $newpath = $courseid . '/' . $gallery->folder . '/_thumb/' . $file . '.jpg';
    if (empty($CFG->gdversion)) {
        return $fallback;
    }
    umask(00);
    if (file_exists($CFG->dataroot . '/' . $newpath)) {
        return lightboxgallery_make_img(lightboxgallery_get_image_url($gallery->id, $file, true));
    } else {
        $thumbdir = $CFG->dataroot . '/' . dirname($newpath);
        if (!file_exists($thumbdir) && !mkdir($thumbdir, $CFG->directorypermissions)) {
            return $fallback;
        }
    }
    $info = lightboxgallery_image_info($oldpath);
    if (!($im = lightboxgallery_imagecreatefromtype($info->imagesize[2], $oldpath))) {
        return $fallback;
    }
    $thumb = lightboxgallery_resize_image($im, $info, THUMB_WIDTH, THUMB_HEIGHT, $offsetx, $offsety);
    if (function_exists('ImageJpeg')) {
        @touch($CFG->dataroot . '/' . $newpath);
        if (ImageJpeg($thumb, $CFG->dataroot . '/' . $newpath, 90)) {
            @chmod($CFG->dataroot . '/' . $newpath, 0666);
            return lightboxgallery_make_img(lightboxgallery_get_image_url($gallery->id, $file, true));
        }
    } else {
        return $fallback;
    }
}