Skip to content

Commit

Permalink
fix(asset-server-plugin): Correctly handle non-integer image dimensions
Browse files Browse the repository at this point in the history
michaelbromley committed Feb 17, 2020
1 parent aff8dd1 commit e28c2b3
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/asset-server-plugin/e2e/asset-server-plugin.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -153,6 +153,16 @@ describe('AssetServerPlugin', () => {
expect(files.length).toBe(2);
});
});

describe('unexpected input', () => {
it('does not error on non-integer width', async () => {
return fetch(`${asset.preview}?w=10.5`);
});

it('does not error on non-integer height', async () => {
return fetch(`${asset.preview}?h=10.5`);
});
});
});

export const CREATE_ASSETS = gql`
4 changes: 2 additions & 2 deletions packages/asset-server-plugin/src/transform-image.ts
Original file line number Diff line number Diff line change
@@ -13,8 +13,8 @@ export async function transformImage(
queryParams: Record<string, string>,
presets: ImageTransformPreset[],
): Promise<sharp.Sharp> {
let targetWidth = +queryParams.w || undefined;
let targetHeight = +queryParams.h || undefined;
let targetWidth = Math.round(+queryParams.w) || undefined;
let targetHeight = Math.round(+queryParams.h) || undefined;
let mode = queryParams.mode || 'crop';
const fpx = +queryParams.fpx || undefined;
const fpy = +queryParams.fpy || undefined;

0 comments on commit e28c2b3

Please sign in to comment.