Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toDataURL() type=string error - need object instead string #47

Closed
marchenko-am opened this issue Jul 26, 2018 · 5 comments
Closed

toDataURL() type=string error - need object instead string #47

marchenko-am opened this issue Jul 26, 2018 · 5 comments

Comments

@marchenko-am
Copy link

/**
 * Get data url
 * @param {string} type - A DOMString indicating the image format. The default type is image/png.
 * @returns {string} A DOMString containing the requested data URI
 * @example
 * imgEl.src = imageEditor.toDataURL();
 *
 * imageEditor.loadImageFromURL(imageEditor.toDataURL(), 'FilterImage').then(() => {
 *      imageEditor.addImageObject(imgUrl);
 * });
 */
toDataURL(type) {
    return this._graphics.toDataURL(type);
}

/**
 * To data url from canvas
 * @param {string} type - A DOMString indicating the image format. The default type is image/png.
 * @returns {string} A DOMString containing the requested data URI.
 */
toDataURL(type) {
    return this._canvas && this._canvas.toDataURL(type);
}

But if i open this._canvas.toDataURL (fabric.js):

/**
 * Exports canvas element to a dataurl image. Note that when multiplier is used, cropping is scaled appropriately
 * @param {Object} [options] Options object
 * @param {String} [options.format=png] The format of the output image. Either "jpeg" or "png"
 * @param {Number} [options.quality=1] Quality level (0..1). Only used for jpeg.
 * @param {Number} [options.multiplier=1] Multiplier to scale by
 * @param {Number} [options.left] Cropping left offset. Introduced in v1.2.14
 * @param {Number} [options.top] Cropping top offset. Introduced in v1.2.14
 * @param {Number} [options.width] Cropping width. Introduced in v1.2.14
 * @param {Number} [options.height] Cropping height. Introduced in v1.2.14
 * @return {String} Returns a data: URL containing a representation of the object in the format specified by options.format
 * @see {@link http:https://jsfiddle.net/fabricjs/NfZVb/|jsFiddle demo}
 * @example <caption>Generate jpeg dataURL with lower quality</caption>
 * var dataURL = canvas.toDataURL({
 *   format: 'jpeg',
 *   quality: 0.8
 * });
 * @example <caption>Generate cropped png dataURL (clipping of canvas)</caption>
 * var dataURL = canvas.toDataURL({
 *   format: 'png',
 *   left: 100,
 *   top: 100,
 *   width: 200,
 *   height: 200
 * });
 * @example <caption>Generate double scaled png dataURL</caption>
 * var dataURL = canvas.toDataURL({
 *   format: 'png',
 *   multiplier: 2
 * });
 */
toDataURL: function (options) {
  options || (options = { });

  var format = options.format || 'png',
      quality = options.quality || 1,
      multiplier = options.multiplier || 1,
      cropping = {
        left: options.left || 0,
        top: options.top || 0,
        width: options.width || 0,
        height: options.height || 0,
      };
  return this.__toDataURLWithMultiplier(format, quality, cropping, multiplier);
}

Object instead string!

@jinwoo-kim-nhn
Copy link
Contributor

@marchenko-am
Sorry, I can not understand this problem.
The 'toDataURL' method of all objects displayed here returns a string.

@marchenko-am
Copy link
Author

@jinwoo-kim-nhn
I mean "type" - argument of method:
toDataURL(type)
Into JsDoc you discribe this as string:

  • @param {string} type - A DOMString indicating the image format.......
    But, really, it is object (into fabric.js) - see JsDoc of fabric.js that I type in previous post.
    I discover this because my PhpStorm indicate warning message in this line: toDataURL(type)

@jinwoo-kim-nhn
Copy link
Contributor

@marchenko-am
Yes. I misunderstood the issue.
thank you. I will fix this notation as soon as possible.

@marchenko-am
Copy link
Author

Hi. this issue was fixed into commit dcfb7ee8e8925ec0bac45a3e83bcbbd87b457b7a
Please, close this issue.

@jinwoo-kim-nhn
Copy link
Contributor

Resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants