misc: swap thumbnail for resize for quality

This commit is contained in:
Xylight committed 2024-07-07 18:54:14 -07:00
1 parent 6bc3c0bd94
commit 289ea0d34e
2 files changed
+22 -16

No files matched your search

+21 -15
View File
@@ -12,18 +12,19 @@ export const bestImageURL = (
compact: boolean = true, compact: boolean = true,
width: number = 1024 width: number = 1024
) => { ) => {
if (width > 1024) { let fetchWidth =
if (post.url) return `${post.url}?format=webp` width > 1024
else if (post.thumbnail_url) return `${post.thumbnail_url}?format=webp` ? // -1 disables a small thumbnail
} -1
: // set width to 512 if compact
compact
? 512
: // otherwise, just use the original width
width
if (compact && post.thumbnail_url) if (post.thumbnail_url)
return `${post.thumbnail_url}?thumbnail=512&format=webp` return optimizeImageURL(post.thumbnail_url, fetchWidth)
else if (compact && post.url) return `${post.url}?thumbnail=512&format=webp` else if (post.url) return optimizeImageURL(post.url, fetchWidth)
if (post.url) return `${post.url}?thumbnail=${width}&format=webp`
else if (post.thumbnail_url)
return `${post.thumbnail_url}?thumbnail=${width}&format=webp`
return post.url ?? '' return post.url ?? ''
} }
@@ -34,11 +35,16 @@ export const optimizeImageURL = (
): string => { ): string => {
try { try {
const url = new URL(urlStr) const url = new URL(urlStr)
url.searchParams.append('format', 'webp') url.searchParams.append('format', 'webp')
url.searchParams.append(
'thumbnail', if (width > 0) {
findClosestNumber([128, 256, 512, 728, 1024, 1536], width).toString() url.searchParams.append(
) 'resize',
findClosestNumber([128, 256, 512, 728, 1024, 1536], width).toString()
)
}
return url.toString() return url.toString()
} catch (e) { } catch (e) {
console.log(e) console.log(e)
+1 -1
View File
@@ -20,7 +20,7 @@
const urlObj = new URL(url) const urlObj = new URL(url)
urlObj.searchParams.append('format', 'webp') urlObj.searchParams.append('format', 'webp')
urlObj.searchParams.append( urlObj.searchParams.append(
'thumbnail', 'resize',
findClosestNumber(sizes, res || width).toString() findClosestNumber(sizes, res || width).toString()
) )