{"record":{"id":"cd586dc04a874b7c","repo":"plotly/plotly.js","slug":"height-and-width-should-be-pixel-values","errorCode":null,"errorMessage":"Height and width should be pixel values.","messagePattern":"Height and width should be pixel values\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/plot_api/to_image.js","lineNumber":107,"sourceCode":"        data = gd.data || [];\n        layout = gd.layout || {};\n        config = gd.config || {};\n        fullLayout = {};\n    } else {\n        gd = Lib.getGraphDiv(gd);\n        data = Lib.extendDeep([], gd.data);\n        layout = Lib.extendDeep({}, gd.layout);\n        config = gd._context;\n        fullLayout = gd._fullLayout || {};\n    }\n\n    function isImpliedOrValid(attr) {\n        return !(attr in opts) || Lib.validate(opts[attr], attrs[attr]);\n    }\n\n    if((!isImpliedOrValid('width') && opts.width !== null) ||\n        (!isImpliedOrValid('height') && opts.height !== null)) {\n        throw new Error('Height and width should be pixel values.');\n    }\n\n    if(!isImpliedOrValid('format')) {\n        throw new Error('Export format is not ' + Lib.join2(attrs.format.values, ', ', ' or ') + '.');\n    }\n\n    var fullOpts = {};\n\n    function coerce(attr, dflt) {\n        return Lib.coerce(opts, fullOpts, attrs, attr, dflt);\n    }\n\n    var format = coerce('format');\n    var width = coerce('width');\n    var height = coerce('height');\n    var scale = coerce('scale');\n    var setBackground = coerce('setBackground');\n    var imageDataOnly = coerce('imageDataOnly');","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/plotly/plotly.js/blob/1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314/src/plot_api/to_image.js#L89-L125","documentation":"Validation guard in Plotly.toImage: when the caller supplies opts.width or opts.height, those values are checked with Lib.validate against the width/height attribute definitions (positive numbers, >=1). The throw fires when a supplied value fails validation and is not null (null means 'use current layout size'). Typical fault: a string like '500px', a CSS-style value, or a non-positive number passed as width/height.","triggerScenarios":"Thrown at src/plot_api/to_image.js:107 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass width and height as plain numbers of pixels, e.g. Plotly.toImage(gd, {format:'png', width:800, height:600}).","Parse numeric values out of any CSS string before passing them (parseInt('500px', 10)).","Pass null (or omit) for width/height to fall back to the graph div's current layout dimensions.","Ensure values are at least 1 and finite."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314","analyzedAt":"2026-09-02T22:03:39.906Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}