lumeland / imagemagick-deno

Deno port of the WASM library for ImageMagick
https://deno.land/x/imagemagick_deno
42 stars 3 forks source link

Opening two files leads to a "instance is disposed" error #11

Closed punarinta closed 10 months ago

punarinta commented 10 months ago

The following code

  await initialize();

  const imageData: Uint8Array = await Deno.readFile('image.png');
  const wmData: Uint8Array = await Deno.readFile('watermark.png')
  const wm: IMagickImage = await new Promise((resolve) => ImageMagick.read(wmData, resolve))

  await ImageMagick.read(imageData, async (img: IMagickImage) => {
    img.composite(wm)
  })

results in the following error

CLI process died because of an error Error: instance is disposed
    at MagickImage.get _instance (https://deno.land/x/imagemagick_deno@0.0.26/src/native-instance.ts:29:11)
    at https://deno.land/x/imagemagick_deno@0.0.26/src/magick-image.ts:1244:15
    at https://deno.land/x/imagemagick_deno@0.0.26/src/internal/exception/exception.ts:36:22
    at Function.use (https://deno.land/x/imagemagick_deno@0.0.26/src/internal/pointer/pointer.ts:27:14)
    at Function.usePointer (https://deno.land/x/imagemagick_deno@0.0.26/src/internal/exception/exception.ts:35:20)
    at MagickImage.composite (https://deno.land/x/imagemagick_deno@0.0.26/src/magick-image.ts:1241:15)
oscarotero commented 10 months ago

This repo contains only the code from https://github.com/dlemstra/magick-wasm converted for Deno compatibility. Can you reproduce this error with the original Node version?

punarinta commented 10 months ago

@oscarotero the code with the original library works well:

const { ImageMagick, initializeImageMagick, MagickFormat } = require('@imagemagick/magick-wasm')
const fs = require('fs')

const imageData = fs.readFileSync('image.png')
const wmData = fs.readFileSync('watermark.png')

const _ = (async () => {
  await initializeImageMagick()

  ImageMagick.read(wmData, wm => {
    ImageMagick.read(imageData, image => {
      image.composite(wm)

      image.write(
        MagickFormat.Jpeg,
        data => fs.writeFileSync('result.png', data),
      )
    })
  })
})()
punarinta commented 10 months ago

Apparantly this was the problem: https://github.com/dlemstra/magick-wasm/issues/93#issuecomment-1563459037 Problem solved. Sorry for a false alarm.