Resize CGSize to the maximum with keeping the aspect-ratio <p>I have a <code>CGSize</code> objects that I need to send to my server. The maximum size I can send to the server is 900*900 (900 width/900 height).</p> <p>There are some objects that are larger the 900*900 and I want to write a function that resizes them to the maximum (as I already say, the maximum is 900*900) but to keep the aspect ratio.</p> <p>For example: if I have an object that is 1,000px width and 1,000px height I want the function to return a 900*900 object. If I have an object that is 1920px width and 1080px height I want it to return the maximum size possible with keeping the ratio.</p> <p>Anyone have any idea how can I do that?</p> <p>Thank you!</p> <p><strong>OriginalUser2 answer:</strong></p> <p>I've tried this code:</p> <pre><code>let aspect = CGSizeMake(900, 900) let rect = CGRectMake(0, 0, 1920, 1080) let final = AVMakeRectWithAspectRatioInsideRect(aspect, rect) </code></pre> <p><code>final</code> is <code>{x 420 y 0 w 1,080 h 1,080}</code>, I can't understand why the <code>x = 420</code>, but anyway <code>1080*1080</code> is not in the same aspect ratio as <code>1920*1080</code> and it's bigger than <code>900*900</code>.</p> <p>Can you explain a bit more?</p>