diff --git a/Cargo.toml b/Cargo.toml
index f72b746a..c9e66bea 100755
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,6 +33,7 @@ js-sys = "0.3.60"
resvg = { version = "0.25.0", default-features = false, features = [
"filter",
"dump-svg",
+ "raster-images",
] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
@@ -41,6 +42,7 @@ napi-derive = "2.9.1"
resvg = { version = "0.25.0", default-features = false, features = [
"filter",
"dump-svg",
+ "raster-images",
"text",
] }
diff --git a/__test__/index.spec.ts b/__test__/index.spec.ts
index 9054c413..8a5e089d 100755
--- a/__test__/index.spec.ts
+++ b/__test__/index.spec.ts
@@ -3,11 +3,54 @@ import { join } from 'path'
import test from 'ava'
import jimp from 'jimp-compact'
+import fetch from 'node-fetch'
import { Resvg, renderAsync } from '../index'
import { jimpToRgbaPixels } from './helper'
+test('Use href to load a JPG image without alpha', async (t) => {
+ const imgUrl = 'http://tva2.sinaimg.cn/crop.0.0.250.250.80/534b48acjw8ehw72edguyj206y06yq32.jpg'
+ const svg = ``
+ const resvg = new Resvg(svg, {
+ font: {
+ loadSystemFonts: false,
+ },
+ })
+ const resolved = await Promise.all(
+ resvg.imagesToResolve().map(async (url) => {
+ console.info('image url', url)
+ const img = await fetch(url)
+ const buffer = await img.arrayBuffer()
+ return {
+ url,
+ buffer: Buffer.from(buffer),
+ }
+ }),
+ )
+ if (resolved.length > 0) {
+ for (const result of resolved) {
+ const { url, buffer } = result
+ resvg.resolveImage(url, buffer)
+ }
+ }
+ const pngData = resvg.render()
+ const resvgPngBuffer = pngData.asPng()
+ const result1 = await jimp.read(resvgPngBuffer)
+
+ const jimpImg = await fetch(imgUrl)
+ const jimpBuffer = await jimpImg.arrayBuffer()
+ const result2 = await jimp.read(jimpBuffer)
+
+ const r1 = new jimp({ data: result1.bitmap.data, width: pngData.width, height: pngData.height })
+ const r2 = new jimp({ data: result2.bitmap.data, width: result2.bitmap.width, height: result2.bitmap.height })
+
+ t.is(result1.hasAlpha(), false)
+ t.is(jimp.diff(r1, r2, 0.01).percent, 0) // 0 means similar, 1 means not similar
+})
+
test('svg to RGBA pixels Array', async (t) => {
const svg = `