function lightboxgallery_resize_upload($filename, $dimensions)
{
    list($width, $height) = explode('x', $dimensions);
    $image = new lightboxgallery_edit_image($filename);
    return $image->resize($width, $height);
}
Exemplo n.º 2
0
function lightboxgallery_index_thumbnail($courseid, $gallery, $file = '')
{
    global $CFG;
    $gallerypath = $CFG->dataroot . '/' . $courseid . '/' . $gallery->folder;
    $indexpath = $gallerypath . '/_thumb/index.png';
    $webpath = $courseid . '/' . $gallery->folder . '/_thumb/index.png';
    if (!file_exists($indexpath) || !empty($file)) {
        if (empty($file)) {
            if (!($images = lightboxgallery_directory_images($gallerypath))) {
                return;
            }
            $file = $images[0];
        }
        $thumbpath = $gallerypath . '/_thumb/' . $file . '.jpg';
        if (!file_exists($thumbpath)) {
            $thumbparent = new lightboxgallery_edit_image($gallerypath . '/' . $file);
            if (!$thumbparent->create_thumbnail()) {
                return;
            }
        }
        $base = new lightboxgallery_edit_image('index.png');
        $thumb = new lightboxgallery_edit_image($thumbpath);
        $transparent = imagecolorat($base->image, 0, 0);
        $shrunk = imagerotate($thumb->resize(48, 48, 0, 0, true), 351, $transparent, 0);
        imagecolortransparent($base->image, $transparent);
        imagecopy($base->image, $shrunk, 2, 3, 0, 0, imagesx($shrunk), imagesy($shrunk));
        if (!$base->save_image($base->image, $indexpath)) {
            return;
        }
    }
    return lightboxgallery_make_img_tag($CFG->wwwroot . '/file.php' . ($CFG->slasharguments ? '/' : '?file=/') . $webpath);
}