
One loop... One Caluculation
OK,<BR><BR>All that loop stuff a half hour ago was just the start.<BR>But this should not be too tough. <BR><BR>My task at hand is to take the dimensions of an image and scale the bugger. This is done with ASPjpeg but that does not matter at this point.<BR><BR>Below shows a brilliant calulation that actually works!<BR><BR><% <BR>Photo1TestH = 3499<BR>Photo1TestW = 210<BR>wFixed = 180<BR>Photo1Test = Photo1TestW / (Photo1TestH / wFixed)<BR> %><BR> <BR><%= Cint(Photo1Test) %><BR><BR>Which gives the correct answer: 11<BR><BR>>>>>>> 2;>>>>>>>> >>>>>>>><B R><BR>OK<BR><BR>Now I want to use the same freaking logic with data.<BR><BR>First I grab the records.<BR><BR>blah blah blah<BR><BR>Then I take this stuff and put it into a few arrays..<BR><BR>lovely and it could look like this<BR><BR><BR><BR><BR> <BR><%<BR>PhotoHeight = Array( 320, 540, 843 )<BR>PhotoWidth = Array( 34, 435, 5666 )<BR> <BR>For i = 0 To 2 <BR>Response.Write "Photo1w =" & PhotoWidth(i) & "<BR>" <BR>Response.Write "Photo1h =" & PhotoHeight(i) & "<BR>" <BR>Response.Write "wFixed =" & wFixed & "<BR>" <BR>Response.Write "Photo1hNew = " & Cint(Cint(PhotoWidth(i))/ (Cint(PhotoHeight(i))/wFixed)) & "<BR><BR>" <BR>Next <BR>%> <BR><BR>The only problem is the values for<BR><BR>Response.Write "Photo1hNew = " & Cint(Cint(PhotoWidth(i))/ (Cint(PhotoHeight(i))/wFixed)) & "<BR><BR>" <BR><BR>are wrong!!!<BR><BR>what gives? Math geniuses anyone?<BR><BR>ideas...<BR><BR>

What's with all the CINTs???
These are *ALREADY* numbers. You don't need or want CINT with them any more.<BR><BR>And you didn't bother to tell/show us what the value of <BR> wFixed<BR>is. Or is it still always 180?<BR><BR>Anyway:<BR> Response.Write "Photo1hNew = " & PhotoWidth(i)/( PhotoHeight(i)/wFixed ) & "<br/>"<BR><BR>??? <BR><BR>But your scaling math makes no sense to me. What is 11 supposed to be in that first answer of yours????<BR><BR>

Just Numbers
Yes wFixed is<BR><BR>wFixed = 180<BR><BR>further down the page<BR><BR>It should read:<BR><BR>Cint((PhotoWidth(i))/ ((PhotoHeight(i))/wFixed))<BR><BR>as this number needs to be an integer<BR>so a few extra Cint the first time.<BR><BR>I thought the math was working but ..<BR><BR>OK.<BR><BR>So you have images with all kinds of sizes. You know their sizes. It is in a DB.<BR><BR>You want to scale them but make them all 180 wide.<BR><BR>What would the math be??<BR><BR>I guess not:<BR><BR>(vImageWidth/(vImageHeight/180))<BR><BR>ideas??<BR><BR>

Sure as heck wouldn't...
...do that.<BR><BR>You want to scale the *height* to a new number, right? Because the *width* is already a given.<BR><BR>so:<BR><BR> newHeight = oldHeight * ( 180 / oldWidth )<BR><BR>Use logic: If the oldWidth is 360, then the new width is 1/2 of the old width, right? So the new height should also be 1/2 of the old height.<BR> 180 / 360 >> 0.5<BR> 0.5 * oldHeight >> newHeight<BR><BR>If the oldWidth is 90, then the new width is twice the old width. Similiarly:<BR> 180 / 90 >> 2.0<BR> 2.0 * oldHeight = newHeight<BR><BR>Etc.<BR><BR>So:<BR> photoNewWidth = wFixed<BR> photoNewHeight = Round( PhotoHeight(i) * ( wFixed / PhotoWidth(i) ) )<BR><BR>[And don't use CINT when you want to do a math operation; use Round or Int or Fix.]<BR><BR>

RE: My real job is...
playing piano...<BR><BR>thanks a ton... I have to go so will get to this tomorrow...<BR><BR>

I think what you were after...
...was<BR> newHeight = oldHeight / ( oldWidth / 180 )<BR><BR>Because that *is* the same, mathematically, as<BR> newHeight = oldHeight * ( 180 / oldWidth )<BR><BR>Do you see it? It's the old "to divide by a fraction, invert it and then multiply" trick, isn't it?<BR><BR>But you had your variables for height and width reversed!<BR><BR>You were picking up a new *width* on the assumption that the *height* would always be 180.<BR><BR><BR>

yep..

Now *that* would be...
...a job to have. Sigh. I can play, but nowhere's near talented enough to keep anybody entertained.<BR><BR>On the other hand, if I ever finish my MIDIized reed organ...<BR><BR>
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

