Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When inserting images that used colorbox, the image dimensions would be undefined. I needed the width for inserting captions, so I added in the following code into insert.js around line 72.
function getWidth(url){
var i=new Image;
i.onload=function(){ i.width = this.width; return i; }
i.src=url;
return i;
}
var width = ($(content).attr("width") != undefined) ? $(content).attr("width") : getWidth($('img', content).attr("src")).width;
Comments
Comment #1
quicksketchHm, we should already have the width on all inserted images. We've got this code in image.inc already:
This makes sure that all images already have a width and height attribute specified on their
<img>
tags. I'm not really sure how you're inserting images using colorbox. Does that module provide integration with Insert directly? Or did you do something custom for your site? In either case, it should be possible to get the height/width attributes on the img tag already, without modification to Insert module.Comment #1.0
quicksketchadded return to function
Comment #2
Snater CreditAttribution: Snater commentedBrowsing through old tickets while working on the module's D8 version. Apart from this ticket being quite old, I am closing it because I cannot reproduce the issue. I have a D7 instance running with Insert and Colorbox enabled. Placing an image using a Colorbox Insert style results in the dimension attributes being applied correctly.