lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.11k stars 1.29k forks source link

No decoding plugin on docker #4229

Closed MohammedQureshi closed 2 weeks ago

MohammedQureshi commented 2 weeks ago

/usr/src/app/sample # npm install --verbose --foreground-scripts sharp npm verb cli /usr/local/bin/node /usr/local/bin/npm npm info using npm@10.2.4 npm info using node@v18.19.1 npm verb title npm install sharp npm verb argv "install" "--loglevel" "verbose" "--foreground-scripts" "sharp" npm verb logfile logs-max:10 dir:/root/.npm/_logs/2024-10-04T07_48_30_784Z- npm verb logfile /root/.npm/_logs/2024-10-04T07_48_30_784Z-debug-0.log npm http fetch GET 200 https://registry.npmjs.org/sharp 269ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-wasm32 81ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-darwin-arm64 219ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-arm64 234ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-arm64 233ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linuxmusl-arm64 237ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linuxmusl-arm64 236ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-darwin-arm64 262ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-darwin-x64 266ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-s390x 274ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-darwin-x64 277ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-win32-x64 282ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-arm 284ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-win32-ia32 285ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-s390x 285ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-arm 303ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/@emnapi%2fruntime 101ms (cache miss) npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-win32-x64 npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-win32-ia32 npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-wasm32 npm verb reify failed optional dependency /usr/src/app/node_modules/@emnapi/runtime npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-linuxmusl-arm64 npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-linux-s390x npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-linux-arm64 npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-linux-arm npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-libvips-linuxmusl-arm64 npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-libvips-linux-s390x npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-libvips-linux-arm64 npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-libvips-linux-arm npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-libvips-darwin-x64 npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-libvips-darwin-arm64 npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-darwin-x64 npm verb reify failed optional dependency /usr/src/app/node_modules/@img/sharp-darwin-arm64 npm http fetch GET 200 https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.2.0.tgz 105ms (cache miss) npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/advisories/bulk 1103ms npm http fetch GET 200 https://registry.npmjs.org/xml2js 731ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/aws-sdk 171ms (cache miss)

up to date, audited 1254 packages in 7s

107 packages are looking for funding run npm fund for details

3 moderate severity vulnerabilities

Some issues need review, and may require choosing a different dependency.

Run npm audit for details. npm verb exit 0 npm info ok

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

System: OS: Linux 6.6 Alpine Linux CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz Memory: 4.68 GB / 7.66 GB Container: Yes Shell: 1.36.1 - /bin/ash Binaries: Node: 18.19.1 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 10.2.4 - /usr/local/bin/npm npmPackages: sharp: ^0.33.5 => 0.33.5

Problem, So I am running sharp on an alpine docker container with NodeJS and I keep getting the error no decoding plugin found, I went on the docker terminal into the app directory and ran the sharp.versions and I can see the heic and the vips installed and others but those are the important ones as I am converting HEIF and HEIC to JPEG and I can see vips installed and has the plugin for HEIF but when ever I run the sharp decoder it just throw an error no decoder found.

image

"message": "source: bad seek to 293616\nheif: Error while loading plugin: No decoding plugin installed for this compression format (11.6003)" "meta":{"correlationId":"3075a0c7-6ce5-45a7-881d-d08434f2604f", "stack": "Error: source: bad seek to 293616\nheif: Error while loading plugin: No decoding plugin installed for this compression format (11.6003)\n at Sharp.toBuffer (/usr/src/app/node_modules/sharp/lib/output.js:163:17)\

const jpegBuffer = await sharp(file.buffer) .jpeg({quality: 80}) .toBuffer();

lovell commented 2 weeks ago

Please see https://github.com/lovell/sharp/issues/4204#issuecomment-2328003124

MohammedQureshi commented 2 weeks ago

I have seen this and doesn't seem to work for me I still am unable to convert HEIC and HEIF inside sharp.

MohammedQureshi commented 2 weeks ago

Here is a sample project if you get some time https://github.com/MohammedQureshi/SharpLibVipTesting

lovell commented 2 weeks ago

Please see https://github.com/strukturag/libheif/issues/1250 - you'll probably need to build libheif from source.

MohammedQureshi commented 2 weeks ago

I also tried this yesterday and didn't seem to have a difference. Any other tips?

lovell commented 2 weeks ago

If you still require help, please update https://github.com/MohammedQureshi/SharpLibVipTesting to include the logic you tried when building libheif from source using the details mentioned in https://github.com/strukturag/libheif/issues/1250

MohammedQureshi commented 2 weeks ago

I have already pushed the update https://github.com/MohammedQureshi/SharpLibVipTesting/blob/9cb35fbd6b8f2bbc4af73512ea9c0cf22ebe94bb/Dockerfile#L42 also the statement -DENABLE_PLUGIN_LOADING=NO does not work on meson build as a param.

lovell commented 2 weeks ago

Thanks for updating, I don't see use of the -DENABLE_PLUGIN_LOADING=NO flag when you're building libheif - please add it. In addition, the latest version of libheif is v1.18.2.

MohammedQureshi commented 2 weeks ago

The latest supported for my Alpine box is 1.16.2 https://pkgs.alpinelinux.org/packages?name=libheif&branch=v3.18&repo=&arch=x86_64&origin=yes&flagged=&maintainer= also didn't realise it was for the libheif I have added it and retested it and pushed the code but get the same exact error

Error converting image: Error: uploads/e89e60f7de8b30a2c6d4c720929e328c: bad seek to 293616 heif: Error while loading plugin: No decoding plugin installed for this compression format (11.6003) at Sharp.toFile (/app/node_modules/sharp/lib/output.js:90:19) at /app/app.js:41:8 at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5) at next (/app/node_modules/express/lib/router/route.js:149:13) at done (/app/node_modules/multer/lib/make-middleware.js:45:7) at indicateDone (/app/node_modules/multer/lib/make-middleware.js:49:68) at /app/node_modules/multer/lib/make-middleware.js:155:11 at WriteStream.<anonymous> (/app/node_modules/multer/storage/disk.js:43:9) at WriteStream.emit (node:events:529:35) at finish (node:internal/streams/writable:748:10)

MohammedQureshi commented 1 week ago

As I am building from source I realised the versions don't matter as of course, I am building it, I updated to the latest but still no luck.

lovell commented 1 week ago

Please see https://sharp.pixelplumbing.com/install#building-from-source and ensure you are also installing all the required dependencies to build from source, including node-addon-api and node-gyp.

MohammedQureshi commented 1 week ago

Yup exact same result, I even tried it the way documented doing --save for local and changed it to global as well which both returns the same results and updated the PR.

sendyputra commented 1 week ago

this Dockerfile working for me but slow build, i use this to combine with alpine-chrome

# FROM zenika/alpine-chrome
FROM asia.gcr.io/zenika-hub/alpine-chrome

USER root

ARG LIBDE265_VERSION=1.0.15
ENV LIBDE265_VERSION=$LIBDE265_VERSION

ARG LIBHEIF_VERSION=1.18.2
ENV LIBHEIF_VERSION=$LIBHEIF_VERSION

ARG VIPS_VERSION=8.15.3
ENV VIPS_VERSION=$VIPS_VERSION

RUN apk add --no-cache \
    tini make gcc g++ python3 git nodejs npm zip

RUN apk add --no-cache \
    cmake autoconf automake libtool meson ninja curl \
    pkgconfig glib-dev expat-dev tiff-dev libjpeg-turbo-dev libgsf libexif libpng-dev cgif libjxl libimagequant

RUN git clone https://chromium.googlesource.com/webm/libwebp && \
    cd libwebp && \
    ./autogen.sh && \
    ./configure && \
    make && \
    make install && \
    cd .. && \
    rm -rf libwebp

RUN git clone https://bitbucket.org/multicoreware/x265_git.git && \
    cd x265_git && \
    cmake source && \
    make && \
    cd .. && \
    rm -rf x265_git

RUN curl -L https://github.com/strukturag/libde265/releases/download/v${LIBDE265_VERSION}/libde265-${LIBDE265_VERSION}.tar.gz | \
    tar zx && \
    cd libde265-${LIBDE265_VERSION} && \
    ./autogen.sh && \
    ./configure && \
    mkdir build && \
    cd build && \
    cmake .. && \
    make && \
    make install && \
    cd ../.. && \
    rm -rf libde265-${LIBDE265_VERSION}

RUN curl -L https://github.com/strukturag/libheif/releases/download/v${LIBHEIF_VERSION}/libheif-${LIBHEIF_VERSION}.tar.gz | \
    tar zx && \
    cd libheif-${LIBHEIF_VERSION} && \
    mkdir build && \
    cd build && \
    cmake -DENABLE_PLUGIN_LOADING=NO --preset=release .. && \
    make && \
    make install && \
    cd ../.. && \
    rm -rf libheif-${LIBHEIF_VERSION}

RUN curl -L https://github.com/libvips/libvips/releases/download/v${VIPS_VERSION}/vips-${VIPS_VERSION}.tar.xz | \
    tar -xJ && \
    cd vips-${VIPS_VERSION} && \
    meson setup build && \
    cd build && \
    meson compile && \
    meson test && \
    meson install && \
    cd ../.. && \
    rm -rf vips-${VIPS_VERSION}

WORKDIR /app

ENV NODE_ENV=production
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PORT=8080
ENV HOSTNAME="0.0.0.0"
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser

RUN npm install -g corepack npm

RUN corepack enable && yarn set version berry

RUN yarn dlx envinfo

COPY . .

COPY package.json yarn.lock .yarnrc.yml ./

RUN yarn install --immutable --inline-builds

RUN npx turbo build

EXPOSE 8080

ENTRYPOINT ["tini", "--"]
CMD ["node", "build/index.js"]
MohammedQureshi commented 6 days ago

I just tried it out and get the same exact issue I updated the github link above idk why this is so complex to run inside docker

Error converting image: Error: uploads/6b44f36c03e16bd7506e53ee71c469ab: bad seek to 42992 heif: Error while loading plugin: No decoding plugin installed for this compression format (11.6003) at Sharp.toFile (/app/node_modules/sharp/lib/output.js:90:19) at /app/app.js:41:8 at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5) at next (/app/node_modules/express/lib/router/route.js:149:13) at done (/app/node_modules/multer/lib/make-middleware.js:45:7) at indicateDone (/app/node_modules/multer/lib/make-middleware.js:49:68) at /app/node_modules/multer/lib/make-middleware.js:155:11 at WriteStream. (/app/node_modules/multer/storage/disk.js:43:9) at WriteStream.emit (node:events:529:35) at finish (node:internal/streams/writable:748:10)

lovell commented 6 days ago

Please see https://sharp.pixelplumbing.com/install#building-from-source and ensure you are also installing all the required dependencies to build from source, including node-addon-api and node-gyp (e.g. add these as dependencies in your package.json file).

MohammedQureshi commented 5 days ago

I have seen that and added those previously it makes no difference I just added them again and still the same outcome.

lovell commented 5 days ago

You've (correctly) added node-gyp and node-addon-api to your package.json so there's no need to install them again. Additionally, you've added SHARP_IGNORE_GLOBAL_LIBVIPS, which does the opposite of what you want, so remove that.

diff --git a/Dockerfile b/Dockerfile
index 18be359..b13310c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -81,10 +81,6 @@ COPY . .

 COPY package.json package-lock.json ./

-RUN npm install --save node-addon-api node-gyp
-
-ENV SHARP_IGNORE_GLOBAL_LIBVIPS=1
-
 RUN npm install --build-from-source

 EXPOSE 3000
MohammedQureshi commented 5 days ago

I tried it without these originally and still gave me the error Error converting image: Error: uploads/24afdcfb0cbc29520a6d6e03cbd906d3: bad seek to 42992 heif: Error while loading plugin: No decoding plugin installed for this compression format (11.6003)

lovell commented 5 days ago

If you still require help, please add a sample image to your repo that allows someone else to reproduce.

MohammedQureshi commented 5 days ago

Ah yes that would be useful I have included these now both HEIC and HEIF

lovell commented 5 days ago

Your repo works on my machine:

git clone https://github.com/MohammedQureshi/SharpLibVipTesting.git
cd SharpLibVipTesting
docker build -t sharplibviptesting .
docker run --rm -it -p 3000:3000 sharplibviptesting

Then use a browser to access http://localhost:3000/

The output of your samples images:

6dd128ea6f31a654b874e1868b02ba2b 487dece2f2230a0cb9c9588b65ff095d

MohammedQureshi commented 5 days ago

That is interesting, You ar running it exactly how I would be running but even with the no cache I still can't get it to work in docker it must be an issue with my local docker then I will try on another PC, Thank you for testing that its going to be annoying if that was the issue all along it just didn't work on my machine, Thank you for testing this!