Browse Source

Fix issue #43

Former-commit-id: 75c241c6c787814779d00e87d5e41e70e876cfa1
pull/17/head
mortenbock 12 years ago
committed by James South
parent
commit
bef5caab91
  1. 40
      src/ImageProcessor/Processors/Resize.cs

40
src/ImageProcessor/Processors/Resize.cs

@ -364,24 +364,26 @@ namespace ImageProcessor.Processors
} }
} }
// Constrain the image to fit the maximum possible height or width. // Constrain the image to fit the maximum possible height or width.
if (resizeMode == ResizeMode.Max) if (resizeMode == ResizeMode.Max)
{ {
if (sourceWidth > width || sourceHeight > height) //If either is 0, we don't need to figure out orientation
{ if (width > 0 && height > 0)
double ratio = Math.Abs(height / width); {
double sourceRatio = Math.Abs(sourceHeight / sourceWidth); //integers must be cast to doubles to get needed precision
double ratio = (double)height / width;
if (sourceRatio < ratio) double sourceRatio = (double)sourceHeight / sourceWidth;
{
height = 0; if (sourceRatio < ratio)
} {
else height = 0;
{ }
width = 0; else
} {
} width = 0;
} }
}
}
// If height or width is not passed we assume that the standard ratio is to be kept. // If height or width is not passed we assume that the standard ratio is to be kept.
if (height == 0) if (height == 0)
@ -669,4 +671,4 @@ namespace ImageProcessor.Processors
return floats; return floats;
} }
} }
} }

Loading…
Cancel
Save