One loop... One Caluculation

# Thread: One loop... One Caluculation

1. Senior Member
Join Date
Dec 1969
Posts
661

## 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>&#060;% <BR>Photo1TestH = 3499<BR>Photo1TestW = 210<BR>wFixed = 180<BR>Photo1Test = Photo1TestW / (Photo1TestH / wFixed)<BR> %&#062;<BR> <BR>&#060;%= Cint(Photo1Test) %&#062;<BR><BR>Which gives the correct answer: 11<BR><BR>&#062;&#062;&#062;&#062;&#062;&#062;&#06 2;&#062;&#062;&#062;&#062;&#062;&#062;&#062;&#062; &#062;&#062;&#062;&#062;&#062;&#062;&#062;&#062;<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>&#060;%<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>%&#062; <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>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## What's with all the CINTs???

These are *ALREADY* numbers. You don&#039;t need or want CINT with them any more.<BR><BR>And you didn&#039;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 ) & "&#060;br/&#062;"<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>

3. Senior Member
Join Date
Dec 1969
Posts
661

## 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>

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## 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 --&#062;&#062; 0.5<BR> 0.5 * oldHeight --&#062;&#062; newHeight<BR><BR>If the oldWidth is 90, then the new width is twice the old width. Similiarly:<BR> 180 / 90 --&#062;&#062; 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&#039;t use CINT when you want to do a math operation; use Round or Int or Fix.]<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
661

## RE: My real job is...

playing piano...<BR><BR>thanks a ton... I have to go so will get to this tomorrow...<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## 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&#039;s the old "to divide by a fraction, invert it and then multiply" trick, isn&#039;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>

7. Senior Member
Join Date
Dec 1969
Posts
661

## yep..

sigh..

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## Now *that* would be...

...a job to have. Sigh. I can play, but nowhere&#039;s near talented enough to keep anybody entertained.<BR><BR>On the other hand, if I ever finish my MIDI-ized 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
•