Skip to content

Commit 9f86e6d

Browse files
committed
fix: heif compression options
1 parent 48f8e7b commit 9f86e6d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/pathToImage.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Buffer } from 'node:buffer'
2-
import { parse as urlParse } from 'node:url'
32
import { match } from 'path-to-regexp'
43
import type { Create, CreateText } from 'sharp'
54
import sharp from 'sharp'
@@ -12,7 +11,7 @@ import type {
1211
ImagePlaceholderQuery,
1312
ImageType,
1413
} from './types'
15-
import { formatColor, formatText, getBackground } from './utils'
14+
import { formatColor, formatText, getBackground, urlParse } from './utils'
1615

1716
export type CreateOptions = Create
1817

@@ -23,14 +22,16 @@ export async function pathToImage(
2322
findPathRule: FindPathRule,
2423
options: Required<ImagePlaceholderOptions>,
2524
): Promise<ImageCacheItem | undefined> {
26-
if (bufferCache.has(url)) {
25+
if (bufferCache.has(url))
2726
return bufferCache.get(url)
28-
}
29-
const { query: urlQuery, pathname } = urlParse(url, true)
27+
28+
const { query: urlQuery, pathname } = urlParse(url)
3029

3130
const rule = findPathRule(pathname!)
3231

33-
if (!rule) return
32+
if (!rule)
33+
return
34+
3435
const urlMatch = match(rule, { decode: decodeURIComponent })(pathname!) || {
3536
params: {
3637
width: options.width,
@@ -83,7 +84,8 @@ export async function pathToImage(
8384
}
8485
bufferCache.set(url, result)
8586
return result
86-
} catch (e) {
87+
}
88+
catch (e) {
8789
console.error(e)
8890
}
8991
}
@@ -103,9 +105,9 @@ export async function createImage({
103105
compressionLevel: number
104106
textColor: string
105107
}) {
106-
if (type === 'svg') {
108+
if (type === 'svg')
107109
return createSVG(create, text.text, textColor)
108-
}
110+
109111
let image = sharp({ create })
110112

111113
text.text = formatText(text.text, textColor)
@@ -121,7 +123,7 @@ export async function createImage({
121123
image = image.webp({ quality })
122124
break
123125
case 'heif':
124-
image = image.heif({ quality })
126+
image = image.heif({ quality, compression: 'av1' })
125127
break
126128
case 'avif':
127129
image = image.avif({ quality })

0 commit comments

Comments
 (0)