Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build_lambda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Create zip bundle
run: |
zip -r deploy.zip . -x "*yarn.lock*" -x "*.git*" -x "*.gitignore*" -x "*deploy.sh*" -x "*package-lock.json*"
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: deploy-${{ github.sha }}
path: deploy.zip
Expand All @@ -42,7 +42,7 @@ jobs:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_PRD }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PRD }}
aws-region: ${{ secrets.AWS_REGION }}
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: deploy-${{ github.sha }}
- name: "Upload dev deployment file"
Expand Down
30 changes: 29 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,34 @@ const extractFeatures = async page => {
}
}

let sharp = null
const resizeCanvas = async (image, resX, resY) => {
if (!sharp) sharp = require("sharp")
const sharpImage = sharp(image)

/**
* TODO: we should eventually get the canvas width/height from the page context
* when running captureCanvas() - can bypass sharp if the image is small enough
*/
// get current image dimensions to check if resize is needed
const metadata = await sharpImage.metadata()
const currentWidth = metadata.width
const currentHeight = metadata.height

// check if current resolution is already <= target resolution
if (currentWidth <= resX && currentHeight <= resY) {
// no resize needed, return original image
return image
}

return sharpImage.resize(resX, resY, { fit: "inside" }).toBuffer()
}
const performCapture = async (
mode,
page,
canvasSelector,
resX,
resY,
gif,
frameCount,
captureInterval,
Expand All @@ -318,14 +342,16 @@ const performCapture = async (
// if the mode is canvas, we need to execute som JS on the client to select
// the canvas and generate a dataURL to bridge it in here
else if (mode === "CANVAS") {
return captureCanvas(
const canvas = await captureCanvas(
page,
canvasSelector,
gif,
frameCount,
captureInterval,
playbackFps
)
if (resX && resY) return resizeCanvas(canvas, resX, resY)
return canvas
}
}

Expand Down Expand Up @@ -647,6 +673,8 @@ exports.handler = async (event, context) => {
mode,
page,
canvasSelector,
resX,
resY,
gif,
frameCount,
captureInterval,
Expand Down
Loading
Loading