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

DNG: Full image VS preview #4307

Open
DidierHoarau opened this issue Dec 30, 2024 · 3 comments
Open

DNG: Full image VS preview #4307

DidierHoarau opened this issue Dec 30, 2024 · 3 comments
Labels

Comments

@DidierHoarau
Copy link

DidierHoarau commented Dec 30, 2024

Question about an existing feature

What are you trying to achieve?

I am trying to convert a DNG to a JPG.

This works but as per my understanding, DNG file contain a small embedded preview. When using sharp the conversion works but it appears to take the embedded preview as input image so the output image is very small.

Example of output:

{
  format: 'jpeg',
  width: 256,
  height: 171,
  channels: 3,
  premultiplied: false,
  size: 8977
}

I would like the conversion to happen on the full image and not the embedded preview. (in the case of my test image the image resolution is 1024x683)

When you searched for similar issues, what did you find that might be related?

No

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question

Script:

const sharp = require("sharp");
const { exiftool } = require("exiftool-vendored");

sharp("photo.DNG")
  .jpeg()
  .toFile("output.jpg", (err, info) => {
    console.log(info, err);
  });

or Dockerfile:

FROM node:22-alpine

WORKDIR /opt/src

RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
    apk add --no-cache --update \
        build-base \
        vips-dev \
        vips-heif \
        fftw-dev \
        imagemagick \
        gcc \
        g++ \
        make \
        python3 \
        wget

RUN npm install node-addon-api && \
    npm install node-gyp

RUN npm install sharp

ARG CACHEBUST=1

COPY photo.DNG /photo.DNG
    
RUN pkg-config --modversion vips-cpp

RUN echo 'const sharp = require("sharp");' > script.js && \
    echo 'sharp("/photo.DNG").jpeg().toFile("output.jpg", (err, info) => { console.log(info, err); });' >> script.js && \
    node script.js

The dockerfile is run with docker build --progress=plain .

Please provide sample image(s) that help explain this question

Can be reproduced with those: https://toolsfairy.com/image-test/sample-dng-files#

@DidierHoarau DidierHoarau changed the title DBG: Full image VS preview DNG: Full image VS preview Dec 30, 2024
@lovell
Copy link
Owner

lovell commented Dec 30, 2024

It looks like you're using a globally-installed libvips compiled with support for ImageMagick, which is the correct approach that will allow you to read DNG images.

In this case, the DNG image is masquerading as a JPEG, and libvips' image loader priority means that libjpeg will used in preference to ImageMagick as it is always much faster when reading JPEG images.

Perhaps you could compile your own libvips without support for JPEG?

@DidierHoarau
Copy link
Author

Hi,

Thanks for the response.

I'm trying to compile libvips without support for JPEG, but no far not succeeded yet.

One workaround so far is for me to install imagemagick and libraw... then first convert the raw images with the "magick" command and then handling the converted images to sharp.

But then question: I understand the behavior but shouldn't this be added to sharp itself as well? (I mean the fact that the full raw image should be processed and not the embedded preview)

Best regards,

@lovell
Copy link
Owner

lovell commented Dec 31, 2024

I've just remembered you can use sharp.block() to skip the JPEG loader.

sharp.block({ operation: ['VipsForeignLoadJpeg'] });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants