Graphics

 View Only
  • 1.  Autosize picture "“ help with some maths

    Posted 06-25-2014 15:12
    I'm trying to modify a script that sets the scales an image to the maximum width/height based on the widthset/heightset variables. I'd like to be able to scale the image to a minimum width/height but I can't wrap my head around the maths.

    [CODE]'get aspect ratio

    picMat.GetDimensions(imageWidth, imageHeight)

    aspect = imageWidth / imageHeight

    'This the code I'd like to edit so that if minmax="MIN" it will scale an image to a minimum width or height

    if ucase(minmax)="MAX" then

    if imageHeight > imageWidth then

    scaleY = heightset / currHeight

    scaleX = (heightset * aspect) / currWidth

    else

    scaleX = widthset / currWidth

    scaleY = (widthset / aspect) / currHeight

    end if

    end if


  • 2.  RE: Autosize picture "“ help with some maths

    Posted 06-25-2014 18:52
    It seems to be behaving better on my second attempt. I don't know why I was having such trouble. I set up the script so that the ScaleX/ScaleY equations in each 'if statement' mirror each other and moved the calculation of the aspect ratio into the 'if statements', and I made sure the aspect ratio calculates to be 1 or greater. This cleared up some confusion for me and for whatever reason it started working correctly.

    else if ucase(minmax)="MIN"

    if imageHeight < imageWidth then 'Apply calculate final dimensions

    aspect = imageWidth / imageHeight

    scaleY = heightset / currHeight

    scaleX = (heightset * aspect) / currWidth

    else

    aspect = imageHeight / imageWidth

    scaleX = widthset / currWidth

    scaleY = (widthset * aspect) / currHeight

    end if

    else


    #XPression