File tree 2 files changed +21
-3
lines changed
2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 62
62
<figcaption >Avif format:</figcaption >
63
63
<NuxtPicture format =" avif" src =" rhino.jpg" />
64
64
</figure >
65
+
66
+ <figure >
67
+ <figcaption >Jpeg format prop with jpg image:</figcaption >
68
+ <NuxtPicture format =" jpeg" src =" rhino.jpg" />
69
+ </figure >
65
70
</div >
66
71
</template >
67
72
Original file line number Diff line number Diff line change @@ -2,6 +2,21 @@ import { joinURL } from 'ufo'
2
2
import type { ImageModifiers , ImageOptions , ResolvedImage } from '@nuxt/image'
3
3
import { useRuntimeConfig } from '#imports'
4
4
5
+ const JPEG_REGEX = / j p e ? g /
6
+
7
+ function addFormatToSrc ( src : string , format : string ) : string {
8
+ const extension = src . split ( '.' ) . pop ( )
9
+
10
+ if (
11
+ extension === format ||
12
+ ( extension ?. match ( JPEG_REGEX ) && format . match ( JPEG_REGEX ) ) // Avoid add `.jpg` to `.jpeg`, and vice versa
13
+ ) {
14
+ return src
15
+ }
16
+
17
+ return src + '.' + format
18
+ }
19
+
5
20
export interface InterventionRequestImageModifiers extends ImageModifiers {
6
21
contrast ?: number
7
22
sharpen ?: number
@@ -79,9 +94,7 @@ export function getImage(
79
94
// process modifiers
80
95
const operationsString = operations . join ( '-' )
81
96
82
- if ( format && ! src . endsWith ( '.' + format ) ) {
83
- src += '.' + format
84
- }
97
+ if ( format ) src = addFormatToSrc ( src , format )
85
98
86
99
const getUrl = function ( ) : string {
87
100
if ( src . match ( '^https?' ) ) {
You can’t perform that action at this time.
0 commit comments