Skip to content

Commit

Permalink
Support WebP image types (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
namoscato authored Apr 16, 2023
1 parent 7657e11 commit cdf7736
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
27 changes: 24 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/exif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down
3 changes: 2 additions & 1 deletion src/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Image> {
private readonly filenames = new Set<string>()
Expand Down

0 comments on commit cdf7736

Please sign in to comment.