Automattic / Automattic/node-canvas

drwaImage with scale or crop render very blur when export pdf file

Open
#1,822 4 comments 0 reactions 0 assignees View on GitHub
Bug Good first issue Help wanted
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

### `drwaImage` with scale or crop render very blur.
[Here is result PDF](https://github.com/Saberjsd/assets/raw/main/comments/canvas/output_1622709280832.pdf)
#### This is preview with 200%:

![preview with 200%](https://raw.githubusercontent.com/Saberjsd/assets/main/comments/canvas/preview_with_200.png)

### I wite a demo for show my problem for export PDF.

```js
const exportPdf = async () => {
const { createCanvas, loadImage } = require('canvas');
const fs = require('fs');
const path = require('path')
let canvasWidth = 200;
let canvasHeight = 200;
const canvas = createCanvas(canvasWidth, canvasHeight, 'pdf');
const ctx = canvas.getContext('2d');
// image is a 800 x 800 px png
const imgUrl = "http://capcium.com/wp-content/themes/capcium/dist/images/-placeholders/img-example-square.png"
let img = await loadImage(imgUrl);
const padding = 100;

ctx.scale(0.1, 0.1)
// draw origin image
ctx.drawImage(img, padding, padding);
// draw image with scale
ctx.drawImage(img, img.width + padding * 2, padding, img.width - 1, img.height - 1);
// draw image with crop
ctx.drawImage(img, 0, 0, img.width - 1, img.height - 1, padding, img.height + padding * 2, img.width, img.height);

const outPath = path.join(__dirname, `./output_${+new Date()}.pdf`)
canvas.createPDFStream().pipe(fs.createWriteStream(outPath));
console.log('end')
}

exportPdf()
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.