PHP image re-sizing
<p>I have a PHP script that re-sizes my JPEG images. But, for some reason The images are being distorted, even though I programmed it to calculate the x or y (depending on the photo orientation) proportionally. The quality is 100, so I don't get why it would be making them distorted. What am I doing wrong?</p>

<p><strong>EDIT</strong></p>

<p>The original image is 3264px x 2448px</p>

<p>The original Image:
<a href="http://imgur.com/DOsKf&amp;hMAOh#0" rel="nofollow">http://imgur.com/DOsKf&amp;hMAOh#0</a></p>

<p>Re-sized: 
<a href="http://imgur.com/DOsKf&amp;hMAOh#1" rel="nofollow">http://imgur.com/DOsKf&amp;hMAOh#1</a></p>

<p>Thanks</p>

<p>The Code:</p>

<pre><code>&lt;?php

$im = ImageCreateFromJpeg('IMG_0168.jpg');

//Find the original height and width.

$ox = imagesx($im);
$oy = imagesy($im);

//Now we will determine the new height and width. For this example maximum height will    
be 500px and the width will be 960px. To prevent inproper proportions we need to know 
if the image is portrate or landscape then set one dimension and caluate the other. 

$height = 500;
$width = 960;
if($ox &lt; $oy)   #portrate
{
   $ny = $height;
   $nx = floor($ox * ($ny / $oy)); 
} 
else #landscape
{
   $nx = $width;
   $ny = floor($oy * ($nx / $ox)); 
} 

//Then next two functions will create a new image resource then copy the original image     
to the new one and resize it.

$nm = imagecreatetruecolor($nx, $ny);
imagecopyresized($nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy);

//Now we just need to save the new file.

imagejpeg($nm, 'smallerimagefile2.jpg', 100);

?&gt;
</code></pre>
