{"record":{"id":"1d997e11c19665b0","repo":"aFarkas/lazysizes","slug":"define-width-or-height-of-image-so-we-can-calcula","errorCode":null,"errorMessage":"Define width or height of image, so we can calculate the other dimension","messagePattern":"Define width or height of image, so we can calculate the other dimension","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"plugins/aspectratio/ls.aspectratio.js","lineNumber":162,"sourceCode":"\t\t\t\t\t\tratioCache[ratio] = match[1] * 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn ratioCache[ratio];\n\t\t\t};\n\t\t})(),\n\t\taddAspectRatio: function(img, notNew){\n\t\t\tvar ratio;\n\t\t\tvar width = img.offsetWidth;\n\t\t\tvar height = img.offsetHeight;\n\n\t\t\tif(!notNew){\n\t\t\t\taddClass(img, 'lazyaspectratio');\n\t\t\t}\n\n\t\t\tif(width < 36 && height <= 0){\n\t\t\t\tif(width || height && window.console){\n\t\t\t\t\tconsole.log('Define width or height of image, so we can calculate the other dimension');\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tratio = this.getSelectedRatio(img);\n\t\t\tratio = this.parseRatio(ratio);\n\n\t\t\tif(ratio){\n\t\t\t\tif(width){\n\t\t\t\t\timg.style.height = (width / ratio) + 'px';\n\t\t\t\t} else {\n\t\t\t\t\timg.style.width = (height * ratio) + 'px';\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tremoveAspectRatio: function(img){\n\t\t\tremoveClass(img, 'lazyaspectratio');\n\t\t\timg.style.height = '';","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/aFarkas/lazysizes/blob/1523a4ff4579e170355c7607f445689b43229caf/plugins/aspectratio/ls.aspectratio.js#L144-L180","documentation":"This is a console warning (console.log) emitted by the lazysizes aspectratio plugin, not an exception. The plugin computes an image's intrinsic aspect ratio to reserve layout space, but it needs at least one real dimension (width or height) to derive the other. When width < 36 and height <= 0, it cannot compute a ratio, logs this message, and returns early without applying the aspect-ratio padding.","triggerScenarios":"Calling plugins/aspectratio/ls.aspectratio.js' getSelectedRatio path on an <img> whose width attribute is missing, zero, tiny (<36px), or invalid, and whose height attribute is <= 0 or absent. Also triggered when data-aspectratio is absent at this stage so no ratio can be derived from attributes.","commonSituations":"Lazy-loaded images marked with the lazyaspectratio class but rendered without width/height attributes; templates that output width=\"0\" or height=\"0\" for placeholder images; CMS-generated markup stripping dimensions; developers adding the plugin but forgetting the required data-aspectratio or dimension attributes; images loaded before dimensions are injected by JS.","solutions":["Add a width or height attribute (larger than 36px for width) to the <img>, or set a valid data-aspectratio attribute so the plugin can compute the other dimension","Verify the markup template outputs non-zero dimensions; fix cases producing width=\"0\" or height=\"0\"","If dimensions are injected later by JS, ensure that happens before the plugin processes the image, or re-trigger lazyloading after injection","Check that the aspectratio plugin is correctly initialized (data-aspectratio selector/class wiring) so ratios are picked up"],"exampleFix":"// before\n<img class=\"lazyaspectratio\" data-src=\"photo.jpg\">\n// after\n<img class=\"lazyaspectratio\" data-src=\"photo.jpg\" data-aspectratio=\"1.5\">","handlingStrategy":"fallback","validationCode":"img.addEventListener('lazybeforeunveil', function () {\n  if (!(parseInt(img.getAttribute('width'), 10) >= 36 || parseInt(img.getAttribute('height'), 10) > 0)) {\n    img.setAttribute('data-aspectratio', '16/9');\n  }\n});","typeGuard":null,"tryCatchPattern":"// This is a console.log, not a thrown error; guard by pre-checking dimensions\nif (parseInt(img.getAttribute('width'), 10) < 36 && parseInt(img.getAttribute('height'), 10) <= 0) {\n  img.setAttribute('data-aspectratio', '16/9'); // fallback ratio\n}","preventionTips":["Define a default data-aspectratio fallback for all images lacking dimensions","Audit templates for images rendered with zero or missing width/height","Add a lint/CI check flagging <img> tags without width, height, or data-aspectratio"],"tags":["console-log","missing-attribute","aspect-ratio","lazyloading","image-dimensions"],"backgroundTag":"missing-image-dimensions","analyzedSha":"1523a4ff4579e170355c7607f445689b43229caf","analyzedAt":"2026-09-03T06:04:17.302Z","contentChangedAt":"2026-09-03T06:04:17.302Z","schemaVersion":2},"datasetVersion":"2026-09-10T12:17:11.382Z"}