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

Support WebP image types #388

Merged
merged 9 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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