Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for explicitly setting the dpi(xres,yres) on TIFF images. #828

Merged
merged 7 commits into from
Jun 3, 2017
Merged

Conversation

YvesBos
Copy link
Contributor

@YvesBos YvesBos commented May 29, 2017

In reference to #823 .
This PR exposes the xres and yres properties from libvips.

http://jcupitt.github.io/libvips/API/current/VipsForeignSave.html#vips-tiffsave

@YvesBos YvesBos changed the title Added support for manually setting the dpi(xres,yres) on TIFF images. Added support for explicitly setting the dpi(xres,yres) on TIFF images. May 29, 2017
Copy link
Owner

@lovell lovell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, thanks for this useful addition. I've added a couple of comments/questions inline.

test/unit/io.js Outdated
.toFile(fixtures.outputTiff, (err, info) => {
if (err) throw err;
assert.strictEqual('tiff', info.format);
assert.strictEqual(image.options.tiffXres, res);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the returned info Object should include xres and yres properties? Or maybe the metadata() operation could provide this? I'd prefer to avoid testing the "private" options internals of a sharp instance.

src/pipeline.h Outdated
@@ -182,6 +184,8 @@ struct PipelineBaton {
tiffCompression(VIPS_FOREIGN_TIFF_COMPRESSION_JPEG),
tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_NONE),
tiffSquash(false),
tiffXres(10),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@YvesBos YvesBos May 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/pipeline.cc Outdated
@@ -809,6 +809,9 @@ class PipelineWorker : public Nan::AsyncWorker {
->set("squash", baton->tiffSquash)
->set("compression", baton->tiffCompression)
->set("predictor", baton->tiffPredictor)));
->set("predictor", baton->tiffPredictor)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added xres, and yres when writing to buffer. However, these values do not get saved when calling the ToBuffer method on a tiff image.
e.g. when I write a test like this:

 it('TIFF setting xres and yres on buffer', function (done) {
    const res = 1000.0; // inputTiff has a dpi of 300 (res*2.54)
    const image = sharp(fixtures.inputTiff)
      .tiff({
        xres: (res),
        yres: (res)
      })
      .toBuffer(function (err, data, info) {
        if (err) throw err;
        sharp(data).metadata(function (err, metadata) {
          if (err) throw err;
          assert.strictEqual(metadata.density, res*2.54); // convert to dpi
          done();
        });
      });
  });

And then write it to disk afterwards or read the metadata, the density is still the same as the original(300dpi).
@lovell do you have any idea why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The position of the brackets are fixed by the way. But the dpi on the buffer is still not working.

@lovell
Copy link
Owner

lovell commented May 31, 2017

Thanks for the updates, looking good.

"I also added xres, and yres when writing to buffer. However, these values do not get saved when calling the ToBuffer method on a tiff image."

Based on the code in thie PR, it sounds like a possible bug in libvips or libtiff itself. I should have a chance to investigate this further at the weekend if you haven't been able to work it out in the meantime.

@lovell
Copy link
Owner

lovell commented Jun 2, 2017

I had a quick look at this branch and added your proposed toBuffer based scenario and the test passed. This was on Linux, using the pre-compiled libvips v8.5.5 binaries.

@coveralls
Copy link

coveralls commented Jun 3, 2017

Coverage Status

Coverage increased (+0.009%) to 99.319% when pulling 4c2b0e1 on YvesBos:master into 361ed98 on lovell:master.

@YvesBos
Copy link
Contributor Author

YvesBos commented Jun 3, 2017

A reinstall of sharp did the trick, pretty weird as I was also on libvips v8.5.5.
Glad it's working though, thanks for your help.

@lovell lovell merged commit d8765f9 into lovell:master Jun 3, 2017
@lovell
Copy link
Owner

lovell commented Jun 3, 2017

Fantastic, thank you very much for this Yves.

@lovell lovell added this to the v0.18.2 milestone Jun 3, 2017
lovell added a commit that referenced this pull request Jun 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants