Forum Discussion

sunny_mody's avatar
sunny_mody
Advisor
11 years ago

Avatar upload - crop image to a set size

Hi,   I want the user to upload an avatar of his choice but he should not be able to crop it, Like there will be a crop selector in dotted border which can be resized, can we disable its resizing....
  • KaelaC's avatar
    9 years ago

    Hi sunny_mody - You can do this in a 2 step process. 

     

    First create a custom component that you will place on the upload avatar page

    <!-- -->
    <@liaAddScript>
    (function($) {
       $(document).one("LITHIUM:updateCoordinates",function() {
           var image = $(".lia-image-cropper-source-container > .lia-quilt-column-alley-left > img");
           var img = new Image();
                function addAspectRatio() {
                    image.data("Jcrop").setOptions({aspectRatio: 1});
                }
                
                function addLater() {
                            if (!image.data("Jcrop")) {
                                    window.setTimeout(addLater, 50);
                            } else {
                                    addAspectRatio();
                            }
                }
                
                img.onload = addLater;
                img.src=image[0].src;
        });
    })(LITHIUM.jQuery);
    </@liaAddScript>

    Then, in the skin properties, set the avatar height and width to be the same:

    size.pixel.avatar_profile_h                                     = 125
    size.pixel.avatar_profile_w                                     = 125
    
    size.pixel.avatar_message_h                                     = 50
    size.pixel.avatar_message_w                                     = 50

    You are now good to go!