Search code examples
jqueryjquery-uiimage-scaling

How to calculate minimum image scale?


I need to setup a jQuery UI slider as an image scaler, yet I need to make sure that it is restricted on the low end to meet minimum size requirements.

Given that I know the following:

  • existing image dimensions
  • minimum width and height
  • all scales are to be proportional

... how do I calculate the minimum scale (as in a percentage) so that scale of the image meets the minimum width and height requirements?

Let me know if that wasn't clear, and I'll try to clarify.


Solution

  • var minWidth = 100,
       minHeight = 100,
        curWidth = 600,
       curHeight = 800,
            minW = minWidth / curWidth,
            minH = minHeight / curHeight 
    
        minScale = Math.max(minW, minH); // .1666666666