({ fileBuffer, config, isLossless })
| 161 | } |
| 162 | |
| 163 | async function processJpeg({ fileBuffer, config, isLossless }) { |
| 164 | const sharpImage = sharp(fileBuffer) |
| 165 | .rotate(); // Rotate image using information from EXIF Orientation tag |
| 166 | |
| 167 | if (!isLossless) { |
| 168 | return sharpImage |
| 169 | .jpeg(config?.jpeg?.lossy || {}) |
| 170 | .toBuffer(); |
| 171 | } |
| 172 | |
| 173 | const inputBuffer = await sharpImage |
| 174 | .toColorspace('srgb') // Replace colorspace (guetzli works only with sRGB) |
| 175 | .jpeg({ quality: 100, optimizeCoding: false }) // Applying maximum quality to minimize losses during image processing with sharp |
| 176 | .toBuffer(); |
| 177 | |
| 178 | const commandOptions = [ |
| 179 | ...optionsToArguments({ |
| 180 | options: config?.jpeg?.lossless || {}, |
| 181 | }), |
| 182 | '-', |
| 183 | '-', |
| 184 | ]; |
| 185 | |
| 186 | return pipe({ |
| 187 | command: guetzli, |
| 188 | commandOptions, |
| 189 | inputBuffer, |
| 190 | }); |
| 191 | } |
| 192 | |
| 193 | function processPng({ fileBuffer, config, isLossless }) { |
| 194 | return sharp(fileBuffer) |
no test coverage detected