       return @imageUrl(size) if _.contains(sizes, size)
     null
 
+  imageSizeDimensionsFor: (size) ->
+    @resizeDimensionsFor(@sizes[size])
+
   resizeDimensionsFor: ({ width, height }) ->
     ratios = _.compact _.map { width: width, height: height }, (value, dimension) =>
       value / @get("original_#{dimension}") if value


  maxHeightForWidth: (width, maxDimension) ->
    aspectRatio = @aspectRatio()
    maxDimension = maxDimension || @get 'original_height'
    if aspectRatio?
      height = Math.round width / @aspectRatio()
      if height > maxDimension then maxDimension else Math.floor(height)


# requires the image mixin
module.exports =
  sizes:
    small: width: 200, height: 200
    tall: width: 260, height: 800
    medium: width: Infinity, height: 260
    large: width: 640, height: 640
    larger: width: 1024, height: 1024

  publicVersions: ->
    _.without(@get('image_versions'), 'normalized')

  # Given a desired width and height, return the image url that won't pixelate
  imageUrlFor: (width, height) ->
    if size = @imageSizeForDimensions width, height
      return @imageUrl size
    @imageUrlForMaxSize()

  imageSizeForDimensions: (width, height) ->
    for key, size of @sizes
      if width <= size.width and height <= size.height
        return key if _.contains @get('image_versions'), key

  imageSizeForHeight: (height) ->
    @imageSizeForDimensions height * @aspectRatio(), height
