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

quicksketch’s picture

Category: bug » support

Hm, we should already have the width on all inserted images. We've got this code in image.inc already:

  // Determine dimensions of the image after the image style transformations.
  $image_info = @image_get_info($vars['file']->uri);
  $vars['width'] = isset($image_info['width']) ? $image_info['width'] : NULL;
  $vars['height'] = isset($image_info['height']) ? $image_info['height'] : NULL;
  image_style_transform_dimensions($vars['style_name'], $vars);

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.

quicksketch’s picture

Issue summary: View changes

added return to function

Snater’s picture

Issue summary: View changes
Status: Active » Closed (cannot reproduce)

Browsing 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.