From cdf7736f388bb450524fe9e8cb5142651607dde4 Mon Sep 17 00:00:00 2001 From: Nick Amoscato Date: Sat, 15 Apr 2023 21:52:49 -0400 Subject: [PATCH] Support WebP image types (#388) --- Dockerfile | 27 ++++++++++++++++++++++++--- README.md | 2 +- src/exif.ts | 2 +- src/images.ts | 3 ++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3f2e915..089fb74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,38 @@ FROM node:18 AS builder WORKDIR /usr/app + COPY package*.json ./ RUN npm ci + COPY tsconfig.json . COPY src ./src + RUN npm run build FROM node:18 -RUN apt-get update \ - && apt-get -y install exiftool \ - && rm -rf /var/lib/apt/lists/* +ENV EXIFTOOL_VERSION 12.60 + +# Install exiftool: https://exiftool.org/install.html#Unix +RUN wget -O exiftool.tar.gz "https://exiftool.org/Image-ExifTool-${EXIFTOOL_VERSION}.tar.gz" && \ + tar -xvf exiftool.tar.gz && \ + cd Image-ExifTool-${EXIFTOOL_VERSION} && \ + perl Makefile.PL && \ + make && \ + make test && \ + make install && \ + cd .. \ + rm exiftool.tar.gz + +# Fix "detected dubious ownership" issue: +# https://github.com/actions/runner-images/issues/6775#issuecomment-1410270956 +# https://github.com/actions/checkout/issues/1169 +RUN git config --system --add safe.directory /github/workspace + WORKDIR /usr/app + COPY package*.json ./ RUN npm ci --only=production + COPY --from=builder /usr/app/lib ./lib + CMD ["node", "/usr/app/lib/main.js"] diff --git a/README.md b/README.md index a37e78c..d39ba98 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## Features -- filters PNG and JPEG files in a commit or pull request +- filters PNG, JPEG, and WebP files in a commit or pull request - optionally scales images proportionally - sets Exif metadata to prevent duplicate compressions - pushes commit with compression metrics diff --git a/src/exif.ts b/src/exif.ts index fb324ed..fa919a7 100644 --- a/src/exif.ts +++ b/src/exif.ts @@ -6,7 +6,7 @@ export enum Tag { } export default class Exif { - private static COMMAND = '/usr/bin/exiftool' + private static COMMAND = '/usr/local/bin/exiftool' constructor(private filename: string) {} diff --git a/src/images.ts b/src/images.ts index a1feab8..6c26370 100644 --- a/src/images.ts +++ b/src/images.ts @@ -3,7 +3,8 @@ import {existsSync} from 'fs' import {getType} from 'mime' import Image from './image' -const SUPPORTED_MIME_TYPES = ['image/jpeg', 'image/png'] +/** @see https://tinypng.com/developers/reference#compressing-images */ +const SUPPORTED_MIME_TYPES = ['image/jpeg', 'image/png', 'image/webp'] export default class Images implements Iterable { private readonly filenames = new Set()