Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
85e143e9
Unverified
Commit
85e143e9
authored
Nov 02, 2020
by
Joe Haddad
Committed by
GitHub
Nov 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rotate image from EXIF data (#18687)
Fixes #18643
parent
2d5dbc48
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
0 deletions
+55
-0
image-optimizer.ts
packages/next/next-server/server/image-optimizer.ts
+2
-0
rotated.js
test/integration/image-component/default/pages/rotated.js
+14
-0
exif-rotation.jpg
...egration/image-component/default/public/exif-rotation.jpg
+0
-0
index.test.js
test/integration/image-component/default/test/index.test.js
+39
-0
No files found.
packages/next/next-server/server/image-optimizer.ts
View file @
85e143e9
...
@@ -259,6 +259,8 @@ export async function imageOptimizer(
...
@@ -259,6 +259,8 @@ export async function imageOptimizer(
try
{
try
{
const
transformer
=
sharp
(
upstreamBuffer
)
const
transformer
=
sharp
(
upstreamBuffer
)
transformer
.
rotate
()
// auto rotate based on EXIF data
const
{
width
:
metaWidth
}
=
await
transformer
.
metadata
()
const
{
width
:
metaWidth
}
=
await
transformer
.
metadata
()
if
(
metaWidth
&&
metaWidth
>
width
)
{
if
(
metaWidth
&&
metaWidth
>
width
)
{
...
...
test/integration/image-component/default/pages/rotated.js
0 → 100644
View file @
85e143e9
import
Image
from
'next/image'
import
React
from
'react'
const
Page
=
()
=>
{
return
(
<
div
>
<
p
>
Hello
World
<
/p
>
<
Image
id
=
"exif-rotation-image"
src
=
"/exif-rotation.jpg"
unsized
/>
<
p
id
=
"stubtext"
>
This
is
the
rotated
page
<
/p
>
<
/div
>
)
}
export
default
Page
test/integration/image-component/default/public/exif-rotation.jpg
0 → 100644
View file @
85e143e9
9.54 KB
test/integration/image-component/default/test/index.test.js
View file @
85e143e9
...
@@ -10,6 +10,7 @@ import {
...
@@ -10,6 +10,7 @@ import {
check
,
check
,
hasRedbox
,
hasRedbox
,
getRedboxHeader
,
getRedboxHeader
,
waitFor
,
}
from
'next-test-utils'
}
from
'next-test-utils'
import
webdriver
from
'next-webdriver'
import
webdriver
from
'next-webdriver'
import
fs
from
'fs-extra'
import
fs
from
'fs-extra'
...
@@ -319,6 +320,44 @@ function runTests(mode) {
...
@@ -319,6 +320,44 @@ function runTests(mode) {
)
)
})
})
}
}
// Tests that use the `unsized` attribute:
if
(
mode
!==
'dev'
)
{
it
(
'should correctly rotate image'
,
async
()
=>
{
let
browser
try
{
browser
=
await
webdriver
(
appPort
,
'/rotated'
)
const
id
=
'exif-rotation-image'
// Wait for image to load:
await
check
(
async
()
=>
{
const
result
=
await
browser
.
eval
(
`document.getElementById(
${
JSON
.
stringify
(
id
)}
).naturalWidth`
)
if
(
result
<
1
)
{
throw
new
Error
(
'Image not ready'
)
}
return
'result-correct'
},
/result-correct/
)
await
waitFor
(
1000
)
const
computedWidth
=
await
getComputed
(
browser
,
id
,
'width'
)
const
computedHeight
=
await
getComputed
(
browser
,
id
,
'height'
)
expect
(
getRatio
(
computedWidth
,
computedHeight
)
/
1000.0
).
toBeCloseTo
(
1.333
,
1
)
}
finally
{
if
(
browser
)
{
await
browser
.
close
()
}
}
})
}
}
}
describe
(
'Image Component Tests'
,
()
=>
{
describe
(
'Image Component Tests'
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment