-3

How i can generate a list with four items which should all have the same aspect ratio all depends on the original resolution of 480x360 ? The original aspect ratio 480x360 Also belonging to the list.

Youtube has an example on it open any video click on share and then on embedd

Now you see the list that i want as same as here described.

1. 420x315

    2. 480x360

3. 640x480
4. 960x720

*Edit i hope you now understand my question

Mars
  • 867
  • 2
  • 13
  • 22
Sascha Heim
  • 301
  • 1
  • 4
  • 15
  • Are you given a list of all valid resolutions? – Mars May 03 '14 at 23:54
  • 1
    Yes divide width by height – Sascha Heim May 03 '14 at 23:56
  • What I asked for, was if you have some kind off array of all resolutions that are...valid. By valid I mean 1280x720, 320x240 etc. Not valid would be some strange like 1067x89. So: Have you got an array with all valid resolutions, from which you must take those with desired ratio? – Mars May 04 '14 at 00:01
  • No please re read my question – Sascha Heim May 04 '14 at 00:22
  • So 8x6 and 64x36 are valid resolutions for your examples respectively? You need some sort of array with resolutions. Then you need to traverse it, check if ratio is equal, and print or do whatever stuff you want with it. Here you will find some possible (valid in terms of usability) resolutions: http://upload.wikimedia.org/wikipedia/commons/thumb/f/f0/Vector_Video_Standards4.svg/749px-Vector_Video_Standards4.svg.png – Mars May 04 '14 at 00:53
  • I have no notion for programming this – Sascha Heim May 04 '14 at 01:02
  • Ive updated my ugly question please review – Sascha Heim May 04 '14 at 03:30
  • I gave you quite extensive answer. You need to know the resolutions beforehand, so you have to prepare some collection of all valid resolutions. Then you look up in this collection and choose the ones that have same aspect ratio. – Mars May 04 '14 at 12:08

2 Answers2

0

900 / 1600 = 0.5625 get half 800 * 0.5625 = 450

To get aspectratio, width * 0.5625 = height

Code

$width = 640;
$height = 480;
$ratio = $height / $width;

function ratio($width){
   return $width * $ratio;
}

echo ratio(1280);
Medda86
  • 1,582
  • 1
  • 12
  • 19
0
<?php

// create class to easily add and store resolutions
class Resolution
{
public $x;
public $y;
}

// create our original resolution and calculate its aspect ratio
$origRes = new Resolution();
$origRes->x = 640;
$origRes->y = 480;
$originalRatio = ($origRes->x / $origRes->y);

// create valid resolution
$firstRes = new Resolution();
$firstRes->x = 1280;
$firstRes->y = 720;

// create another resolution
$secondRes = new Resolution();
$secondRes->x = 320;
$secondRes->y = 240;

// ...and so on; two are enough for the example
// you must learn about arrays and came up with proper solution how to populate them

// create array of resolutions from existing resolutions
$arrayOfRes = array($firstRes, $secondRes);

// another way of adding could be: $arrayOfRes[] = $thirdRes

// because floating point values aren't perfect on computers,
// we need some range value to check if the values are "close enough"
// in other words: it's our precision
$epsilon = 0.00001;

// iterate over all elements in array
foreach ($arrayOfRes as $res)
{
// calculate ratio
$ratio = $res->x / $res->y;

// abs - absolute value, thus always positive
// we check if difference is precise enough and print some text
if(abs($ratio - $originalRatio) < $epsilon)
echo'print it here or do something';
}
?>

That's my ten-minute-answer code as non-PHP programmer. I assume this code is valid, but there might be some errors.

[EDIT]

Checked with ideone.com, fixed minor bugs, and now it works as it should. https://ideone.com/lpW9DM

Mars
  • 867
  • 2
  • 13
  • 22