This repository was archived by the owner on May 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
initial support for next/image on netlify #138
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { copySync } = require("fs-extra"); | ||
const { join } = require("path"); | ||
const { NEXT_IMAGE_FUNCTION_NAME, TEMPLATES_DIR } = require("../config"); | ||
|
||
// Move our next/image function into the correct functions directory | ||
const setupImageFunction = (functionsPath) => { | ||
const functionName = `${NEXT_IMAGE_FUNCTION_NAME}.js`; | ||
const functionDirectory = join(functionsPath, functionName); | ||
|
||
copySync(join(TEMPLATES_DIR, "imageFunction.js"), functionDirectory, { | ||
overwrite: false, | ||
errorOnExist: true, | ||
}); | ||
}; | ||
|
||
module.exports = setupImageFunction; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const jimp = require("jimp"); | ||
|
||
// Function used to mimic next/image and sharp | ||
exports.handler = async (event) => { | ||
const { url, w = 500, q = 75 } = event.queryStringParameters; | ||
const width = parseInt(w); | ||
const quality = parseInt(q); | ||
|
||
const imageUrl = url.startsWith("/") | ||
? `${process.env.URL || "http://localhost:8888"}${url}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure about this ||, but i think it's fine since ntl dev uses 8888 as its default port right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is probably okay in the short term, but the port is configurable. quick fix is the create a |
||
: url; | ||
const image = await jimp.read(imageUrl); | ||
|
||
image.resize(width, jimp.AUTO).quality(quality); | ||
|
||
const imageBuffer = await image.getBufferAsync(image.getMIME()); | ||
|
||
return { | ||
statusCode: 200, | ||
headers: { | ||
"Content-Type": image.getMIME(), | ||
}, | ||
body: imageBuffer.toString("base64"), | ||
isBase64Encoded: true, | ||
}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about these defaults but i think it's fine since next_image should almost always provide
w
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably want some reasonable default just in case so we don't end up trying to process 6MB images at full res or whatever, but I think you're right that it should always be set