Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 1.20 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. App Engine: Calculating the dimensions of thumbnails to be generated by serving thumbnails from the blobstore
  2. from __future__ import division
  3. def resized_size(original_width, original_height, width, height):
  4.     original_ratio = float(original_width) / float(original_height)
  5.     resize_ratio = float(width) / float(height)
  6.     if original_ratio >= resize_ratio:
  7.         return int(width), int(round(float(width) / float(original_ratio)))
  8.     else:
  9.         return int(round(float(original_ratio) * float(height))), int(height)
  10.        
  11. import math
  12.  
  13. def rint(x):
  14.   x_int = int(x)
  15.   x_rem = x - x_int  # this is problematic
  16.   if (x_int % 2) == 1:
  17.     return round(x)
  18.   else:
  19.     if x_rem <= 0.5:
  20.       return math.floor(x)
  21.     else:
  22.       return math.ceil(x)
  23.        
  24. import math
  25.  
  26. def rint(x):
  27.   x_int = int(x)
  28.   x_rem = x - x_int
  29.   if (x_int % 2) == 1:
  30.     return round(x)
  31.   else:
  32.     if x_rem - 0.5 < 0.001:
  33.       return math.floor(x)
  34.     else:
  35.       return math.ceil(x)
  36.        
  37. // In Java
  38. double aspectRatio = originalWidth / originalHeight;
  39. output_width = 800;
  40. output_height = (int)Math.round(800.0 / aspectRatio);
  41.        
  42. aspectRatio == 1.3063063063063063
  43. output_width == 32
  44. output_height == Math.round(32.0 / 1.3063063063063063) == 24