Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Resize images based on aspect ratio?

Hi.

I want to tweak the image resizer to differentiate between 'portrait' and 'lanscape' shots. Basically, if a shot is taller than it is wide, I want it to only occupy about 45 per cent of the post container, meaning that a user could post two portrait shots side by side at the same combined width as a single landscape image.

Is this possible? I've looked at the resizer code in global.js and have no idea what it's doing.

D.

Comments

  • Options
    hgtonighthgtonight ∞ · New Moderator

    Welcome to the community!

    What version number of Vanilla are you running?

    I am sure it is possible. The resizing code and approach would be different based on your version of Vanilla.

    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.

  • Options

    Cheers for the quick reply.

    I'm running 2.1b1.

  • Options
    hgtonighthgtonight ∞ · New Moderator

    You can hook in after the image has been resized using the following JS.

    jQuery(window).bind('ImagesResized', function() {
      // wait until all the images have been resized before working with them
      $('div.Message img').each(function() {
        // Do whatever you want in here.
    
        // You can get the natural width or height using the below code:
        var nWidth = $(this).naturalWidth();
        var nHeight = $(this).naturalHeight();
      });
    });
    

    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.

  • Options
    djh_djh_ New
    edited February 2014

    Thanks for this! In the end I went with:

    jQuery(window).bind('ImagesResized', function() {
      // wait until all the images have been resized before working with them
      $('div.Message img').each(function() {
        // Do whatever you want in here.
        // You can get the natural width or height using the below code:
        var container = $(this).closest('div.Message'); 
        if($(this).width() < $(this).height()) {
        $(this).css("max-width", "49%");    
        } else {
            $(this).css("max-width", "99%");    
        }
        $(this).css("margin-right", "1%");      
        // var nWidth = $(this).naturalWidth();
        // var nHeight = $(this).naturalHeight();
      });
    });
    

    (how do you input code in this thing?)

  • Options
    ShadowdareShadowdare r_j MVP
    edited February 2014

    @djh_, I edited your post and put the code in a block with three tildes before and after the code like ~~~.

    Add Pages to Vanilla with the Basic Pages app

Sign In or Register to comment.