Skip to content

Commit

Permalink
Ensure ICC profiles are removed from PNG output #521
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Jul 21, 2016
1 parent 9ddc817 commit 032bb7e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Requires libvips v8.3.1
[#511](https://github.com/lovell/sharp/pull/511)
[@mhirsch](https://github.com/mhirsch)

* Ensure ICC profiles are removed from PNG output unless withMetadata used.
[#521](https://github.com/lovell/sharp/issues/521)
[@ChrisPinewood](https://github.com/ChrisPinewood)

#### v0.15.1 - 12<sup>th</sup> July 2016

* Concat Stream-based input in single operation for ~+3% perf and less GC.
Expand Down
10 changes: 8 additions & 2 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -884,9 +884,12 @@ class PipelineWorker : public AsyncWorker {
baton->formatOut = "jpeg";
baton->channels = std::min(baton->channels, 3);
} else if (baton->formatOut == "png" || (baton->formatOut == "input" && inputImageType == ImageType::PNG)) {
// Strip profile
if (!baton->withMetadata) {
vips_image_remove(image.get_image(), VIPS_META_ICC_NAME);
}
// Write PNG to buffer
VipsArea *area = VIPS_AREA(image.pngsave_buffer(VImage::option()
->set("strip", !baton->withMetadata)
->set("compression", baton->compressionLevel)
->set("interlace", baton->progressive)
->set("filter", baton->withoutAdaptiveFiltering ?
Expand Down Expand Up @@ -961,9 +964,12 @@ class PipelineWorker : public AsyncWorker {
baton->formatOut = "jpeg";
baton->channels = std::min(baton->channels, 3);
} else if (baton->formatOut == "png" || isPng || (matchInput && inputImageType == ImageType::PNG)) {
// Strip profile
if (!baton->withMetadata) {
vips_image_remove(image.get_image(), VIPS_META_ICC_NAME);
}
// Write PNG to file
image.pngsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
->set("strip", !baton->withMetadata)
->set("compression", baton->compressionLevel)
->set("interlace", baton->progressive)
->set("filter", baton->withoutAdaptiveFiltering ?
Expand Down
16 changes: 16 additions & 0 deletions test/unit/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,22 @@ describe('Image metadata', function() {
});
});

it('Remove metadata from PNG output', function(done) {
sharp(fixtures.inputJpgWithExif)
.png()
.toBuffer(function(err, buffer) {
if (err) throw err;
sharp(buffer).metadata(function(err, metadata) {
if (err) throw err;
assert.strictEqual(false, metadata.hasProfile);
assert.strictEqual('undefined', typeof metadata.orientation);
assert.strictEqual('undefined', typeof metadata.exif);
assert.strictEqual('undefined', typeof metadata.icc);
done();
});
});
});

it('File input with corrupt header fails gracefully', function(done) {
sharp(fixtures.inputJpgWithCorruptHeader)
.metadata(function(err) {
Expand Down

0 comments on commit 032bb7e

Please sign in to comment.