Skip to content

Commit

Permalink
Breaking: change default to keep icc profiles #244
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jan 2, 2025
1 parent f986a76 commit 263f5fa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,16 @@ class Image {

// src should be a file path to an image or a buffer
async resize(input) {
let sharpImage = sharp(input, Object.assign({
let sharpInputImage = sharp(input, Object.assign({
// Deprecated by sharp, use `failOn` option instead
// https://github.com/lovell/sharp/blob/1533bf995acda779313fc178d2b9d46791349961/lib/index.d.ts#L915
failOnError: false,
}, this.options.sharpOptions));

// Must find the image format from the metadata
// File extensions lie or may not be present in the src url!
let metadata = await sharpImage.metadata();
let metadata = await sharpInputImage.metadata();

let outputFilePromises = [];

let fullStats = this.getFullStats(metadata);
Expand All @@ -582,7 +583,7 @@ class Image {
continue;
}

let sharpInstance = sharpImage.clone();
let sharpInstance = sharpInputImage.clone();
let transform = this.options.transform;
if(transform) {
if(typeof transform !== "function") {
Expand All @@ -592,6 +593,9 @@ class Image {
await transform(sharpInstance);
}

// https://github.com/11ty/eleventy-img/issues/244
sharpInstance.keepIccProfile();

// Output images do not include orientation metadata (https://github.com/11ty/eleventy-img/issues/52)
// Use sharp.rotate to bake orientation into the image (https://github.com/lovell/sharp/blob/v0.32.6/docs/api-operation.md#rotate):
// > If no angle is provided, it is determined from the EXIF data. Mirroring is supported and may infer the use of a flip operation.
Expand Down
Binary file added test/issue-244-sharp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1234,3 +1234,25 @@ test("#184: Ensure original size is included if any widths are larger", async t
t.is(stats.jpeg[0].width, 900);
t.is(stats.jpeg[1].width, 1280);
});

// https://github.com/lovell/sharp/blob/main/test/fixtures/prophoto.png
test("Keep ICC Profiles by default #244 test image from Sharp repo", async t => {
let inputMetadata = await sharp("./test/issue-244-sharp.png").metadata();

let stats = await eleventyImage("./test/issue-244-sharp.png", {
widths: ["auto"],
formats: ["auto"],
outputDir: "./test/img/",
dryRun: true
});

// output buffer has icc profile
let outputMetadata = await sharp(stats.png[0].buffer).metadata();

t.true(Buffer.isBuffer(inputMetadata.icc));
t.true(inputMetadata.hasProfile);

t.is(stats.png[0].outputPath, path.join("test/img/KmVobkU8Sj-1.png"));
t.true(Buffer.isBuffer(outputMetadata.icc));
t.true(outputMetadata.hasProfile);
});

0 comments on commit 263f5fa

Please sign in to comment.