Modifying the alt text of an imageIn some cases you may want to modify the alt text of an Image without changing the image.
const imageNodes = await framer.getNodesWithAttributeSet("backgroundImage")
for (const imageNode of imageNodes) {
if (!imageNode.backgroundImage) continue
await imageNode.setAttributes({
backgroundImage: imageNode.backgroundImage.cloneWithAttributes({
altText: "Updated Alt Text"
}),
})
}const imageNodes = await framer.getNodesWithAttributeSet("backgroundImage")
for (const imageNode of imageNodes) {
if (!imageNode.backgroundImage) continue
await imageNode.setAttributes({
backgroundImage: imageNode.backgroundImage.cloneWithAttributes({
altText: "Updated Alt Text"
}),
})
}const imageNodes = await framer.getNodesWithAttributeSet("backgroundImage")
for (const imageNode of imageNodes) {
if (!imageNode.backgroundImage) continue
await imageNode.setAttributes({
backgroundImage: imageNode.backgroundImage.cloneWithAttributes({
altText: "Updated Alt Text"
}),
})
} Example: Image ProcessingSome plugins may be designed to manipulate images. For these cases, we provide raw image bytes and some utilities to perform image manipulation. A convenient way to perform image manipulation is by rendering the Image bitmap on a HTML canvas. An example implementation of bytesFromCanvas can be found in this gist.
const image = await framer.getImage()
const canvas = document.createElement("canvas")
const ctx = canvas.getContext("2d")
const bitmap = await image.loadBitmap()
ctx.canvas.width = img.width;
ctx.canvas.height = img.height;
ctx.scale(-1, 1);
ctx.drawImage(bitmap, -bitmap.width, 0);
const result = await bytesFromCanvas(canvas);
await framer.addImage({
image: { bytes: result, mimeType },
});
const image = await framer.getImage()
const canvas = document.createElement("canvas")
const ctx = canvas.getContext("2d")
const bitmap = await image.loadBitmap()
ctx.canvas.width = img.width;
ctx.canvas.height = img.height;
ctx.scale(-1, 1);
ctx.drawImage(bitmap, -bitmap.width, 0);
const result = await bytesFromCanvas(canvas);
await framer.addImage({
image: { bytes: result, mimeType },
});
const image = await framer.getImage()
const canvas = document.createElement("canvas")
const ctx = canvas.getContext("2d")
const bitmap = await image.loadBitmap()
ctx.canvas.width = img.width;
ctx.canvas.height = img.height;
ctx.scale(-1, 1);
ctx.drawImage(bitmap, -bitmap.width, 0);
const result = await bytesFromCanvas(canvas);
await framer.addImage({
image: { bytes: result, mimeType },
}); Working with FilesCode components can be configured to accept files by adding ControlType.File to the component's property controls. A Plugin can upload files to Framer and assign them to the component's controls using the following code.
const uploadedFile = await framer.uploadFile({
file: "https://example.com/video.mp4",
name: "Example Video"
})
await framer.addComponentInstance({
url: "https://framer.com/m/framer/Video.js#Video",
attributes: {
controls: {
srcType: "Upload",
srcFile: uploadedFile,
},
},
})const uploadedFile = await framer.uploadFile({
file: "https://example.com/video.mp4",
name: "Example Video"
})
await framer.addComponentInstance({
url: "https://framer.com/m/framer/Video.js#Video",
attributes: {
controls: {
srcType: "Upload",
srcFile: uploadedFile,
},
},
})const uploadedFile = await framer.uploadFile({
file: "https://example.com/video.mp4",
name: "Example Video"
})
await framer.addComponentInstance({
url: "https://framer.com/m/framer/Video.js#Video",
attributes: {
controls: {
srcType: "Upload",
srcFile: uploadedFile,
},
},
}) Working with SVGsAdding an SVG uses the addSVG async function. You can pass in the html for the SVG itself, along with a name of your choosing. Only SVG smaller than 10kb is accepted.
await framer.addSVG({
svg: `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20"><path d="M5 2.5h10v5h-5Zm0 5h5l5 5H5Zm5 5v5l-5-5Z"/></svg>`,
name: "framer.svg",
})await framer.addSVG({
svg: `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20"><path d="M5 2.5h10v5h-5Zm0 5h5l5 5H5Zm5 5v5l-5-5Z"/></svg>`,
name: "framer.svg",
})await framer.addSVG({
svg: `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20"><path d="M5 2.5h10v5h-5Zm0 5h5l5 5H5Zm5 5v5l-5-5Z"/></svg>`,
name: "framer.svg",
})If you need to pass SVG bigger than 10kb, you should pass it's bytes data using the addImage function.
await framer.addImage({
image: {
type: "bytes",
bytes: new TextEncoder().encode(svgInput),
mimeType: "image/svg+xml",
},
name: "SVG",
});await framer.addImage({
image: {
type: "bytes",
bytes: new TextEncoder().encode(svgInput),
mimeType: "image/svg+xml",
},
name: "SVG",
});await framer.addImage({
image: {
type: "bytes",
bytes: new TextEncoder().encode(svgInput),
mimeType: "image/svg+xml",
},
name: "SVG",
});