title: Resize image preserving aspect ratio in Tensorflow
body: <p>I am fairly new to TF. I am trying to resize an image tensor so that the lowest dimension of the image is a constant value LO_DIM.
  In a non-tf environment, I'd just do something like this:</p>
  
  <pre><code>if img.size[0] &lt; img.size[1]:
      h = int(float(LO_DIM * img.size[1]) / img.size[0])
      img = resize(img, [LO_DIM, h])
  else:
      w = int(float(LO_DIM * img.size[0]) / img.size[1])
      img = resize(img, [w, LO_DIM])
  </code></pre>
  
  <p>I know that, to resize I should use <code>tf.image.resize_images</code>, but I am not sure how to compute the new <code>w</code> and <code>h</code> considering that the tensor seems to have <code>shape=&lt;unknown&gt;</code>.</p>
  
  <p>Note: each image I'm passing might have different sizes, that's why I need it to be computed dynamically. And I'm using LO_DIM to keep aspect ratio and not distort the image.</p>
  
  <p>Any suggestions on how to achieve this?</p>
  
  <p>If it helps, the processing goal is to get a random NxN patch from the scaled image, but all I could find is <code>resize_image_with_crop_or_pad</code> which doesn't seem to do the initial scaling.</p>