title: PHP resize image keeping aspect ratio to exact size
body: <p>I need to manually find DPI of new image.</p>
  
  <pre><code>$input_width = 361;
  $input_height = 413;
  
  $input_dpi_x = 72;
  $input_dpi_y = 72;
  
  $output_width = 800;
  $output_height = $input_height * $output_width / $input_width;
  
  $output_dpi_x = ceil(($input_dpi_x / $input_width) * $output_width);
  $output_dpi_y = ceil(($input_dpi_y / $input_height) * $output_y_res);
  
  echo "Outpud_dpi_x = " . $output_dpi_x;
  //Outpud_dpi_x = 160
  </code></pre>
  
  <p>Why when i resize image i get 802 instead of 800?</p>
  
  <p>and i must use DPI dont ask why</p>