/** * Samples a random thumb from the specified gallery and compares dimensions against Config settings * @param Integer Gallery ID * @return Boolean True if size has changed, false if not. */ function thumbSizeChanged($gid) { global $rsgConfig; $gallery = rsgGalleryManager::_get($gid); $images = $gallery->items(); foreach ($images as $image) { $imgname[] = $image->name; } $image = array_rand($imgname); $imgdata = getimagesize(imgUtils::getImgThumb($imgname[$image], true)); if ($imgdata[0] == $rsgConfig->get('thumb_width')) { return false; } else { return true; } }
/** * Function will regenerate thumbs for a specific gallery or set of galleries * @todo Check if width really changed, else no resize needed. * Perhaps by sampling the oldest thumb from the gallery and checking dimensions against current setting. */ function executeRegenerateImages() { global $rsgConfig, $mainframe; $error = 0; $gid = rsgInstance::getVar('gid', array()); if (empty($gid)) { $mainframe->redirect("index2.php?option=com_rsgallery2&rsgOption=maintenance&task=regenerateThumbs", JText::_('NO_GALLERY_SELECTED')); return; } foreach ($gid as $id) { if ($id > 0) { //Check if resize is really needed. It takes a lot of resources when changing thumbs when dimensions did not change! if (!rsg2_maintenance::thumbSizeChanged($id)) { $mainframe->redirect("index2.php?option=com_rsgallery2&rsgOption=maintenance&task=regenerateThumbs", JText::_('THUMBNAIL_SIZE_DID_NOT_CHANGE_REGENERATION_NOT_NEEDED')); return; } else { $gallery = rsgGalleryManager::_get($id); $images = $gallery->items(); foreach ($images as $image) { $imagename = imgUtils::getImgOriginal($image->name, true); if (!imgUtils::makeThumbImage($imagename)) { //Error counter $error++; } } } } } if ($error > 0) { $msg = JText::_('MAINT_REGEN_ERRORS'); } else { $msg = JText::_('MAINT_REGEN_NO_ERRORS'); } $mainframe->redirect("index2.php?option=com_rsgallery2&rsgOption=maintenance&task=regenerateThumbs", $msg); }
/** * returns an array of galleries from an array of IDs * @param id of the gallery */ function _getArray($cid) { $galleries = array(); foreach ($cid as $gid) { $galleries[] = rsgGalleryManager::_get($gid); } return $galleries; }