Skip to content

Commit a8209d7

Browse files
committed
perf: ⚡️ Use the option to prevent images from being enlarged
1 parent 2472113 commit a8209d7

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

src/cli/index.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ type GetOptimizeResultProps = {
2222
nonCacheMeasurement: () => void
2323
cliProgressBarIncrement: () => void
2424
originalFilePath: string
25-
originalWidth: number
2625
sharpOptions?: Config['sharpOptions']
2726
} & Omit<Manifest[number], 'src'>
2827
type GetOptimizeResult = (getOptimizeResultProps: GetOptimizeResultProps) => Promise<void>
@@ -36,7 +35,6 @@ export const getOptimizeResult: GetOptimizeResult = async ({
3635
nonCacheMeasurement,
3736
cliProgressBarIncrement,
3837
originalFilePath,
39-
originalWidth,
4038
output,
4139
width,
4240
quality,
@@ -75,9 +73,7 @@ export const getOptimizeResult: GetOptimizeResult = async ({
7573
const imageBuffer = fs.readFileSync(originalFilePath)
7674
const image = sharp(imageBuffer, { sequentialRead: true })
7775

78-
const resizeWidth = Math.min(originalWidth, width)
79-
80-
image.rotate().resize({ width: resizeWidth })
76+
image.rotate().resize({ width, withoutEnlargement: true })
8177

8278
switch (extension) {
8379
case 'jpeg':
@@ -137,7 +133,6 @@ export const optimizeImages = async ({ manifestJsonPath, noCache, config }: Opti
137133

138134
for (const item of manifest) {
139135
const originalFilePath = path.join(destDir, item.src)
140-
const originalWidth = (await sharp(originalFilePath).metadata()).width ?? 1280
141136

142137
promises.push(
143138
getOptimizeResult({
@@ -149,7 +144,6 @@ export const optimizeImages = async ({ manifestJsonPath, noCache, config }: Opti
149144
nonCacheMeasurement: () => (measuredNonCache += 1),
150145
cliProgressBarIncrement,
151146
originalFilePath,
152-
originalWidth,
153147
sharpOptions: config.sharpOptions ?? {},
154148
...item,
155149
})

0 commit comments

Comments
 (0)