MCPcopy Create free account
hub / github.com/343dev/optimizt / processJpeg

Function processJpeg

optimize.js:163–191  ·  view source on GitHub ↗
({ fileBuffer, config, isLossless })

Source from the content-addressed store, hash-verified

161}
162
163async 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
193function processPng({ fileBuffer, config, isLossless }) {
194 return sharp(fileBuffer)

Callers 1

processFileByFormatFunction · 0.85

Calls 2

optionsToArgumentsFunction · 0.90
pipeFunction · 0.85

Tested by

no test coverage detected