Skip to content

Commit

Permalink
fix: parse width and height modifiers
Browse files Browse the repository at this point in the history
helps to avoid accidentally passing wrong input (also stripping px)
  • Loading branch information
pi0 committed Jan 15, 2021
1 parent 8f806be commit dd2bf78
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/runtime/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { hasProtocol, joinURL } from 'ufo'
import requrl from 'requrl'
import type { ImageOptions, CreateImageOptions, ResolvedImage } from '../types/image'
import { imageMeta } from './utils/meta'
import { parseSize } from './utils'

export interface ImageCTX {
options: CreateImageOptions,
Expand Down Expand Up @@ -122,7 +123,14 @@ function resolveImage (ctx: ImageCTX, input: string, options: ImageOptions): Res
const { provider, defaults } = getProvider(ctx, options.provider || ctx.options.provider)
const preset = getPreset(ctx, options.preset)

const image = provider.getImage(input, { ...defaults, ...options })
const _options = { ...defaults, ...options }
if (_options.modifiers?.width) {
_options.modifiers.width = parseSize(_options.modifiers.width)
}
if (_options.modifiers?.height) {
_options.modifiers.height = parseSize(_options.modifiers.height)
}
const image = provider.getImage(input, _options)

if (process.server && !hasProtocol(image.url)) {
const url = requrl(ctx.nuxtContext.ssrContext.req)
Expand Down

0 comments on commit dd2bf78

Please sign in to comment.