Skip to content

Commit

Permalink
feat(server): implemented alternative image transformers
Browse files Browse the repository at this point in the history
Separated image transformation logic into new functions that allow choosing between performance and
platform support.
  • Loading branch information
Josh-McFarlin committed Jan 21, 2022
1 parent 1db21c5 commit 01d0bcc
Show file tree
Hide file tree
Showing 17 changed files with 2,753 additions and 64 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Moved image transformation logic into separate files to later support additional platforms.
- Created new image transformer that uses Jimp to transform images with pure JavaScript.

### Changed

- Switched default image transformer to Jimp support all platforms by default

## [0.1.6] - 2022-01-21

### Changed
Expand Down
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Where the `responsive` sizes provided through the props are turned into image UR

To install this library and its peer deps, use on of the following commands:
```bash
npm install -S remix-image hybrid-disk-cache sharp
yarn add remix-image hybrid-disk-cache sharp
npm install -S remix-image hybrid-disk-cache sharp jimp
yarn add remix-image hybrid-disk-cache sharp jimp
```

---
Expand Down Expand Up @@ -80,6 +80,31 @@ export const loader: LoaderFunction = ({ request }) => {
**Note:**
Due to [remix request purging](https://remix.run/docs/en/v1.1.1/other-api/serve), `MemoryCache` will clear itself automatically on each request in development. This will not occur during production, and it will perform as expected.
#### Transformer Types
| Name | Description |
|-------|------------------------------------------------------------------------------------|
| Jimp | The default image transformer, supports all platforms at the cost of performance. |
| Sharp | A faster image transformer that uses the file-system, offers the best performance. |
#### Platforms Without File-System Access
Some platforms like Cloudflare workers do not support file-systems and some Node packages.
In this case, use `MemoryCache` and `jimpTransformer` because they are pure JavaScript.
```typescript jsx
import type { LoaderFunction } from "remix";
import { imageLoader, MemoryCache, jimpTransformer } from "remix-image/server";

const config = {
selfUrl: "http://localhost:3000",
whitelistedDomains: ["i.imgur.com"],
cache: new MemoryCache(),
transformer: jimpTransformer,
};

export const loader: LoaderFunction = ({ request }) => {
return imageLoader(config, request);
};
```
---
### Component
Expand Down
3 changes: 2 additions & 1 deletion example/app/routes/api/image.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { LoaderFunction } from "remix";
// eslint-disable-next-line import/no-unresolved
import { imageLoader, DiskCache } from "remix-image/server";
import { imageLoader, DiskCache, sharpTransformer } from "remix-image/server";

const config = {
selfUrl: "http://localhost:3000",
whitelistedDomains: ["i.imgur.com"],
cache: new DiskCache(),
transformer: sharpTransformer,
};

export const loader: LoaderFunction = ({ request }) => {
Expand Down
Loading

0 comments on commit 01d0bcc

Please sign in to comment.