Browse Source

Tweaking the center calculation abit

Former-commit-id: 01d955f39dec3aa02dda11f50c0850a72c56c636
pull/17/head
perploug 12 years ago
parent
commit
bfd551ea89
  1. 16
      src/ImageProcessor/Processors/Resize.cs

16
src/ImageProcessor/Processors/Resize.cs

@ -297,11 +297,13 @@ namespace ImageProcessor.Processors
if (centerCoordinates.Any())
{
destinationY = (int)((centerCoordinates[0] * sourceHeight) * ratio) - (height / 2);
if (destinationY < 0)
var center = -(ratio * sourceHeight) * centerCoordinates[0];
destinationY = (int)center + (height / 2);
if (destinationY > 0)
destinationY = 0;
if (destinationY + height > (sourceHeight * ratio))
if (destinationY < (int)(height - (sourceHeight * ratio)))
destinationY = (int)(height - (sourceHeight * ratio));
}
else
@ -328,11 +330,13 @@ namespace ImageProcessor.Processors
if (centerCoordinates.Any())
{
destinationX = (int)((centerCoordinates[1] * sourceWidth) * ratio) - (width / 2);
if (destinationX < 0)
var center = -(ratio * sourceWidth) * centerCoordinates[1];
destinationX = (int)center + (width / 2);
if (destinationX > 0)
destinationX = 0;
if (destinationX + width > (sourceWidth * ratio))
if (destinationX < (int)(width - (sourceWidth * ratio)))
destinationX = (int)(width - (sourceWidth * ratio));
}
else

Loading…
Cancel
Save