function process_form() { $button = required_param('button', PARAM_TEXT); switch ($button) { case $this->buttonresize: $size = required_param('size', PARAM_INT); list($width, $height) = explode('x', $this->resizeoptions[$size]); break; case $this->buttonscale: $scale = required_param('scale', PARAM_INT); $imagesize = getimagesize($this->imagepath); $width = $imagesize[0] * ($scale / 100); $height = $imagesize[1] * ($scale / 100); break; } $info = lightboxgallery_image_info($this->imagepath); if ($im = lightboxgallery_imagecreatefromtype($info->imagesize[2], $this->imagepath)) { $resized = lightboxgallery_resize_image($im, $info, $width, $height); $this->save_image_resource($resized, $info->imagesize[2]); } }
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; } }
} $resizeoption = 0; if (in_array($gallery->autoresize, array(AUTO_RESIZE_UPLOAD, AUTO_RESIZE_BOTH))) { $resizeoption = $gallery->resize; } else { if (isset($formdata->resize)) { $resizeoption = $formdata->resize; } } if ($resizeoption > 0) { $resizeoptions = lightboxgallery_resize_options(); $fullpath = $CFG->dataroot . '/' . $uploaddir . '/' . $filename; $info = lightboxgallery_image_info($fullpath); if ($im = lightboxgallery_imagecreatefromtype($info->imagesize[2], $fullpath)) { list($width, $height) = explode('x', $resizeoptions[$resizeoption]); if ($resized = lightboxgallery_resize_image($im, $info, $width, $height)) { switch ($info->imagesize[2]) { case 1: $function = 'ImageGIF'; break; case 2: $function = 'ImageJPEG'; break; case 3: $function = 'ImagePNG'; break; } if (function_exists($function)) { $function($resized, $fullpath, $info->imagesize[2] == 3 ? 9 : 100); } }