What's the best practice for image resizing?
v2.1
Images are breaking the comment div, what's the best solution for this issue?
Thanks!
Tagged:
0
Best Answer
-
hgtonight
MVP
I figured it out. The bootstrap theme is missing the needed CSS rule. It needs the following rules:
.Message img { max-width: 100%; }Perhaps @Kasper can confirm?
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
5
Answers
Are you using a custom theme?
The default js will resize images in the message list and add a link to the original full size image.
Is this not the case on your forum?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
@hgtonight No, it's not the case for me it seems. Big images always break the container. I'm using Bootstrap theme.
Is there a global.js file being loaded in your head element?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
This?
<script src="/js/global.js?v=2.1" type="text/javascript"></script>Global.js
// Shrink large images to fit into message space, and pop into new window when clicked. // This needs to happen in onload because otherwise the image sizes are not yet known. jQuery(window).load(function() { /* Adds .naturalWidth() and .naturalHeight() methods to jQuery for retreaving a normalized naturalWidth and naturalHeight. // Example usage: var nWidth = $('img#example').naturalWidth(), nHeight = $('img#example').naturalHeight(); */ (function($){ var props = ['Width', 'Height'], prop; while (prop = props.pop()) { (function (natural, prop) { $.fn[natural] = (natural in new Image()) ? function () { return this[0][natural]; } : function () { var node = this[0], img, value; if (node.tagName.toLowerCase() === 'img') { img = new Image(); img.src = node.src, value = img[prop]; } return value; }; }('natural' + prop, prop.toLowerCase())); } }(jQuery)); jQuery('div.Message img').each(function(i,img) { var img = jQuery(img); var container = img.closest('div.Message'); if (img.naturalWidth() > container.width() && container.width() > 0) { img.after('<div class="ImageResized">' + gdn.definition('ImageResized', 'This image has been resized to fit in the page. Click to enlarge.') + '</div>'); img.wrap('<a href="'+$(img).attr('src')+'"></a>'); } }); // Let the world know we're done here jQuery(window).trigger('ImagesResized'); }); if(typeof String.prototype.trim !== 'function') { String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); } }Go to the page where the images aren't resized. Right click on the page and select View Page source. Once that opens, hit Ctrl+f and type in
global.jsand see if it is found.Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Yes.
<script src="/js/global.js?v=2.1" type="text/javascript"></script>Do you have any errors in your web console?
Ctrl+Shift+K opens it in Firefox. Once open, reload the page.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Use of getPreventDefault() is deprecated. Use defaultPrevented instead. jquery.min.js:3
Under any of these images, do you see a resized message?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Unfortunately no, not a single resized image in any thread. What's the issue?
I figured it out. The bootstrap theme is missing the needed CSS rule. It needs the following rules:
.Message img { max-width: 100%; }Perhaps @Kasper can confirm?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
I can indeed confirm—responsive images is a separate component in Bootstrap and it seems I've forgotten to implement it. Fix coming right up!
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
Excellent. Working!! Thanks a ton, so easy, so smooth...
Actually that's the first thing I've done, add the css rule, unfortunately for me I'm a n00b and I've added .Comment .Message img { width: xxx height: auto; } pfff...