PDF"/>
我目前在 ReactJS 应用程序中使用 pdf-lib 版本 1.17.1 来生成一些文档。目前我已经将文本写入页面,以及嵌入图像并显示它。但是,我需要将图像裁剪成一个圆圈,事实证明,使用其他解决方案所建议的方法无法从库中使用各种方法很困难: 在 pdflib 中将图像拟合成椭圆
我当前运行的代码如下所示:
// Define the ellipse parameters
const ellipseX = 338 + (414 / 2); // X-coordinate of the ellipse center
const ellipseY = (currentY + 95) - (414 / 2); // Y-coordinate of the ellipse center
const ellipseWidth = 200; // Width of the ellipse
const ellipseHeight = 200; // Height of the ellipse
//
agentBioPage.pushOperators(
pushGraphicsState(),
...drawEllipse({
x: ellipseX,
y: ellipseY,
xScale: ellipseWidth,
yScale: ellipseHeight,
rotate: degrees(0),
borderColor: rgb(0, 0, 0), // Border color (black)
borderWidth: 1, // Border width (1 point)
opacity: 1, // Opacity (fully opaque)
blendMode: 'Normal' // Blend mode (normal)
}),
clip(),
)
// Draw the image onto the page
agentBioPage.drawImage(embeddedProfilePicture, {
x: ellipseX - ellipseWidth,
y: ellipseY - ellipseHeight,
width: ellipseWidth * 2,
height: ellipseHeight * 2,
})
//
agentBioPage.pushOperators(popGraphicsState())
它在圆圈上绘制,在图像上绘制,但根本不剪裁图像(这里椭圆位于图像后面):
任何建议、提示和技巧将不胜感激!
干杯
回答如下:更多推荐
发布评论