MATHS - sore head.

EdinburghGary

Reply not Report
Suspended / Banned
Messages
19,271
Name
Gary
Edit My Images
Yes
Writing the gallary software for my new site. Struggling to work out a simple equation, tired and been at it all night - brain now shutting down...

What I want to do is specifcy the original width and height of an image when I upload it, for example 1200 wide, 900 high.

I then want to work out Aspect Ratio based on a new width of 600.

So....is it as simple as this:

600 / original width x 100 = percentage of original size

old height x percentage pf original size = new height



Real example (1024 x 768 original size):

600 / 1024 x 100 = 58.59%

768 x 58.9% = 450

New image size = 600 x 450

Does this new size maintain aspect ratio with 1024 x 768?

Argh brain sore.

Gary.
 
not sure why you want a percentage.

600/1024 x 768 = 450

edit
1024:768 = 1.333:1

600:450 = 1.333:1
 
we use that equation at work all the time for working out medication volumes.
But shouldn't the second equation be.

What you want ie 58.9 / what you have 768 x 100?? er no that doesn't work, hang on er now my head hurts.
 
its what you want divided by what you have times the volume its in. ok maybe that only works with liquid. Use RobertP way that works, why cares how?
 
The aspect ratio of 1024 by 768 is 1024/768 = 1.333

The aspect ratio of 600 x 450 is 600/450 = 1.333

So you got it right.

Andrew

PS: Strictly, the aspect ratio is the width squared divided by the area, which in the first case is: (1024*1024)/(1024*768) but this only comes into play for things that arn't rectangular
 
What I am trying to do, is upload a variety of different full sizes, which don't stick to any rules in terms of standard aspects etc. I might choose to upload a custom sized paronamic 1600 x 500 image, or a vertical paronamic of 700 x 2000...

Every time I need to make a 600 wide "copy" which maintains aspect ratio, therefore by having a percentage, I can then work out the new height based on the percentage that 600 is of the original width....

My maths is PANTS, so perhaps percentages is not the right way...

Gary.
 
So to get the ration you need, do the following.

(original height / original width ) * 600 = your new height.

for example, an 800*600 image will get resized like this...
(800/600) * 600 =
(0.75) * 600 =
450.

or for your later example...
(500 / 1600) * 600 =
(0.3125) * 600 =
187.5

In this case, you'll obviously need to take a call on whether you want to go 600x187 or 600x188.

I think... :)
 
What I am trying to do, is upload a variety of different full sizes, which don't stick to any rules in terms of standard aspects etc. I might choose to upload a custom sized paronamic 1600 x 500 image, or a vertical paronamic of 700 x 2000...

Every time I need to make a 600 wide "copy" which maintains aspect ratio, therefore by having a percentage, I can then work out the new height based on the percentage that 600 is of the original width....

My maths is PANTS, so perhaps percentages is not the right way...

Gary.

Why don't you just open pic in Photoshop, then save for web, input 600 width into image size, make sure width and height are locked together, click apply and it will automatically resize and you can forget the math.
 
OK I have run my first test using this:

Decimal OriginalBitmapWidth = myBitmap.Width;
Decimal OriginalBitmapHeight = myBitmap.Height;
Decimal PercentageToApply = (600 / OriginalBitmapWidth * 100);
Decimal NewBitmapHeight = (OriginalBitmapHeight / 100 * PercentageToApply);


And the results:

Original Image Size:
800 x
562

Percentage to be applied
75.00%

New Size Based on Percentage
600 x 421.5000


Looks like a result...?
 
So to get the ration you need, do the following.

(original height / original width ) * 600 = your new height.

for example, an 800*600 image will get resized like this...
(800/600) * 600 =
(0.75) * 600 =
450.

or for your later example...
(500 / 1600) * 600 =
(0.3125) * 600 =
187.5

In this case, you'll obviously need to take a call on whether you want to go 600x187 or 600x188.

I think... :)



This looks like a neater solution!!

Above works, but looks like I can save a few lines with yours.

G.
 
Are you coding this in .Net / C#? If so, and you need a hand give me a shout. :)
 
Why don't you just open pic in Photoshop, then save for web, input 600 width into image size, make sure width and height are locked together, click apply and it will automatically resize and you can forget the math.

I was able to do that but wasn't clear on the calculations in my head. All working now, the latest poster has managed to save me a few lines of code too with his simpler calc...

The whole point of what I am doing is when I upload one image to my site, it generates a thumbnail, larger view, and full size (intead of doing 3 uploads). A new page on the site with meta data and other info for example photo notes, date taken location etc will be added.

Realise I could use Flickr and other commercial sites, but I enjoy programming and need the experience in .NET!! Also much more satisfying when it all clicks into place...eventually!! :bang::bang::bang:

Gary.
 
Want to drop me a PM with the stuff that's bothering you, and I'll take a look when I get time. :)
 
Back
Top