Max Image Size..

Last post 02-11-2013, 8:42 PM by Sky_Chief. 2 replies.
Sort Posts: Previous Next
  •  02-04-2013, 3:03 PM 76792

    Max Image Size..

    Is there a way to limit the size (not file size) of an image that is inserted?

    I want to keep images less then xxx pixels wide when they are put on a page.


    Self praise is no recommendation
  •  02-05-2013, 12:38 PM 76800 in reply to 76792

    Re: Max Image Size..

    Hi Sky_Chief,

     

    You can use the code below to change the image size if it large than the value you set. the width is set to 400px below, you can limit the height as the same way. Just need to add the code to the bottom of your page, it will automatically perform.

     

    1. <script>  
    2. function CuteEditor_FilterHTML(editor,code)     
    3. {     
    4.     var editdoc = editor.GetDocument();  
    5.     for(var i=0;i<editdoc.images.length;i++)  
    6.     {  
    7.         if(editdoc.images[i].width>400)  
    8.         {  
    9.             editdoc.images[i].width=400;  
    10.         }  
    11.     }  
    12.     return code;  
    13. }     
    14. function CuteEditor_FilterCode(editor,code)     
    15. {     
    16.          var editdoc = editor.GetDocument();  
    17.     for(var i=0;i<editdoc.images.length;i++)  
    18.     {  
    19.         if(editdoc.images[i].width>400)  
    20.         {  
    21.             editdoc.images[i].width=400;  
    22.         }  
    23.     }  
    24.     return code;  
    25. }  
    26. </script>  
     

    Regards,

     

    Ken 

  •  02-11-2013, 8:42 PM 76848 in reply to 76800

    Re: Max Image Size..

    Ken,

    Thanks for the response. The fuction is exactly what I needed.

     

    For other following in my footsteps here is what I did with it.

    Since my application was not concerned about height but only width, I adjusted it to suit my needs and pasted the changes below.

    Now if an image is wider then my column (600 in my case), it will resize it porportionatly both by figuring out how much wider the image is then my limit and subtracting that amount from both the width and height. It is now doing exactly what I was hoping for.

     

    <script> 
    function CuteEditor_FilterHTML(editor,code)    
    {    
        var editdoc = editor.GetDocument(); 
        for(var i=0;i<editdoc.images.length;i++) 
        { 
            if(editdoc.images[i].width>600) 
            { 
                 var currwidth = editdoc.images[i].width
                 var makelessby = currwidth - 600
                 editdoc.images[i].width= currwidth - makelessby  
                     var currheight =  editdoc.images[i].height

                     if(currheight > makelessby)

                      {

                            currheight = currheight - makelessby

                            editdoc.images[i].height = currheight

                      }
      } 
        } 
        return code; 
    }    
    function CuteEditor_FilterCode(editor,code)    
    {    
             var editdoc = editor.GetDocument(); 
        for(var i=0;i<editdoc.images.length;i++) 
        { 
            if(editdoc.images[i].width>600) 
            { 
               var currwidth = editdoc.images[i].width
       var makelessby = currwidth - 600
       editdoc.images[i].width= currwidth - makelessby 

                     var currheight =  editdoc.images[i].height

                     if(currheight > makelessby)

                      {

                            currheight = currheight - makelessby

                            editdoc.images[i].height = currheight

                     }

          }  
        } 
        return code; 

    </script>


    Self praise is no recommendation
View as RSS news feed in XML