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

feat: add experimental image orientation fix #724

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion packages/core/src/__tests__/apply-transforms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('applyTransforms', () => {
expect(metadata).not.toHaveProperty('iptc')
})

it('metadata stripping can be disabled', async () => {
it('metadata stripping can be disabled via boolean', async () => {
const t = vi.fn((i) => i)

const { metadata } = await applyTransforms([t], img, false)
Expand All @@ -40,6 +40,16 @@ describe('applyTransforms', () => {
expect(metadata).toHaveProperty('xmp')
})

it('metadata stripping can be disabled via options object', async () => {
const t = vi.fn((i) => i)

const { metadata } = await applyTransforms([t], img, { removeMetadata: false })

expect(t).toBeCalled()
expect(metadata).toHaveProperty('icc')
expect(metadata).toHaveProperty('xmp')
})

it('returns the image data & info', async () => {
const t = vi.fn((i) => i)

Expand Down
27 changes: 24 additions & 3 deletions packages/core/src/lib/apply-transforms.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
import type { Sharp } from 'sharp'
import type { ImageTransformation, TransformResult } from '../types.js'
import type { ApplyTransformsOptions, ImageTransformation, TransformResult } from '../types.js'
import { METADATA } from './metadata.js'

const defaultOptions: ApplyTransformsOptions = {
removeMetadata: true
}

export async function applyTransforms(
transforms: ImageTransformation[],
image: Sharp,
options?: ApplyTransformsOptions
): Promise<TransformResult>
export async function applyTransforms(
transforms: ImageTransformation[],
image: Sharp,
removeMetadata = true
removeMetadata?: boolean
): Promise<TransformResult>
export async function applyTransforms(
transforms: ImageTransformation[],
image: Sharp,
optionsOrRemoveMetadata?: ApplyTransformsOptions | boolean
): Promise<TransformResult> {
const opts = {
...defaultOptions,
...(typeof optionsOrRemoveMetadata === 'boolean'
? { removeMetadata: optionsOrRemoveMetadata }
: optionsOrRemoveMetadata)
}

image[METADATA] = { ...(await image.metadata()) }

if (removeMetadata) {
if (opts.removeMetadata) {
// delete the private metadata
delete image[METADATA].exif
delete image[METADATA].iptc
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading