Skip to main content
stavrosf25836892
Participant
January 25, 2019
Answered

Problem developing plugin/extension for Adobe XD

  • January 25, 2019
  • 2 replies
  • 380 views

Hey guys,

im currently developing a plugin for Adobe XD.

At some point the extension will access an image uploaded, and convert it to a pixel representation for further processing.

For this code out of the npm package get-image-pixel is used, shown below:

/****************************** Code Block *********************************/ module.exports = function(image, opts) {

    opts = opts||{}

    opts.x = opts.x||0

    opts.y = opts.y||0

    opts.width = typeof opts.width === 'number' ? opts.width : image.width

    opts.height = typeof opts.height === 'number' ? opts.height : image.height

   

    if (!context) {

          canvas = document.createElement("canvas")

-->     context = canvas.getContext('2d')

    }

    canvas.width = opts.width

    canvas.height = opts.height

    context.clearRect(0,0,opts.width,opts.height)

    context.drawImage(image, opts.x, opts.y, opts.width, opts.height, 0, 0, opts.width, opts.height)

    var imgData

    try {

        imgData = context.getImageData(0, 0, opts.width, opts.height)

    } catch(e){

        module.exports.dispose()

        throw e

    }

    return imgData.data

}

/****************************** Code Block *********************************/

The problem i'm facing now is when trying to get the context of the created canvas (indicated by the little arrow in the Code Block).

The thrown problem is:

Plugin TypeError: canvas.getContext is not a function

Interestingly enough the created canvas is a owner document of the following form rather than a canvas element:

My guess is that it has something to do with the adobe xd environment and the creating of the canvas element is not working as

it would in a browser.

My guess is that it has something to do the t

{ _ownerDocument:

   { _ownerDocument: [Circular],

     _selectorEngine:

      { _document: [Circular],

        _styleSheetList: {},

        _styleNodes: {},

        _styleSheets: [],

        _styleNodesMutation: 0,

        _linkNodesMutation: 0,

        _cachedNodeList: null,

        _cachedEnclosingClassNames: {},

.....

Do you have any idea how to solve this problem or even another way to get the pixel representation of an image? You would really help me out!

This topic has been closed for replies.
Correct answer Preran

We have a separate platform for plugin developers https://forums.adobexdplatform.com/top/all

Can you post your question here?

Thanks,

Preran

2 replies

Participant
November 27, 2023

Hi, Sir i have latest version of Adobe Xd but there is problem That my plugin is not going to install there was a problem that this app is not capatible for this version 

 

Preran
Community Manager
PreranCommunity ManagerCorrect answer
Community Manager
January 25, 2019

We have a separate platform for plugin developers https://forums.adobexdplatform.com/top/all

Can you post your question here?

Thanks,

Preran

stavrosf25836892
Participant
January 25, 2019

Yes sure!