mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-02-20 12:19:03 +00:00
Better image thumbnailer
Images smaller than 200x200 will no longer be resized upwards, instead they will be padded with transparent pixels. This was the old behavior before we switched from GM to sharp. With GM, its resize() function would do exactly that, but I couldn't figure out how to do the same with only sharp's resize() function, so I had to make do with a combination of resize() and extend(). Also updated error messages in dashboard when trying to load out-of-index page in uploads/users lists. Updated v1 version string due to dashboard.js being modified.
This commit is contained in:
parent
31a6940ab4
commit
765f8c9880
@ -162,12 +162,34 @@ utilsController.generateThumbs = (name, force) => {
|
||||
alpha: 0
|
||||
}
|
||||
}
|
||||
return sharp(path.join(__dirname, '..', config.uploads.folder, name))
|
||||
.resize(resizeOptions)
|
||||
.toFile(thumbname)
|
||||
const image = sharp(path.join(__dirname, '..', config.uploads.folder, name))
|
||||
return image
|
||||
.metadata()
|
||||
.then(metadata => {
|
||||
if (metadata.width > resizeOptions.width || metadata.height > resizeOptions.height) {
|
||||
return image
|
||||
.resize(resizeOptions)
|
||||
.toFile(thumbname)
|
||||
} else if (metadata.width === resizeOptions.width && metadata.height === resizeOptions.height) {
|
||||
return image
|
||||
.toFile(thumbname)
|
||||
} else {
|
||||
const x = resizeOptions.width - metadata.width
|
||||
const y = resizeOptions.height - metadata.height
|
||||
return image
|
||||
.extend({
|
||||
top: Math.floor(y / 2),
|
||||
bottom: Math.ceil(y / 2),
|
||||
left: Math.floor(x / 2),
|
||||
right: Math.ceil(x / 2),
|
||||
background: resizeOptions.background
|
||||
})
|
||||
.toFile(thumbname)
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if (!error) return resolve(true)
|
||||
console.error(`${name}: ${error.message.trim()}`)
|
||||
console.error(`${name}: ${error.toString()}`)
|
||||
fs.symlink(thumbUnavailable, thumbname, error => {
|
||||
if (error) console.error(error)
|
||||
resolve(!error)
|
||||
|
@ -312,7 +312,7 @@ page.getUploads = function ({ album, pageNum, all } = {}, element) {
|
||||
if (pageNum && (response.data.files.length === 0)) {
|
||||
// Only remove loading class here, since beyond this the entire page will be replaced anyways
|
||||
if (element) page.isLoading(element, false)
|
||||
return swal('An error occurred!', 'There are no more uploads.', 'error')
|
||||
return swal('An error occurred!', `There are no more uploads to populate page ${pageNum + 1}.`, 'error')
|
||||
}
|
||||
|
||||
page.currentView = 'uploads'
|
||||
@ -1585,7 +1585,7 @@ page.getUsers = function ({ pageNum } = {}, element) {
|
||||
if (pageNum && (response.data.users.length === 0)) {
|
||||
// Only remove loading class here, since beyond this the entire page will be replaced anyways
|
||||
if (element) page.isLoading(element, false)
|
||||
return swal('An error occurred!', 'There are no more users!', 'error')
|
||||
return swal('An error occurred!', `There are no more users to populate page ${pageNum + 1}.`, 'error')
|
||||
}
|
||||
|
||||
page.currentView = 'users'
|
||||
|
@ -15,7 +15,7 @@
|
||||
v2: Images and config files (manifest.json, browserconfig.xml, etc).
|
||||
v3: CSS and JS files (libs such as bulma, lazyload, etc).
|
||||
#}
|
||||
{% set v1 = "DXJsv4Spfk" %}
|
||||
{% set v1 = "f7el9u61UI" %}
|
||||
{% set v2 = "Ii3JYKIhb0" %}
|
||||
{% set v3 = "ll7yHY3b2b" %}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user