Skip to content

Help regarding using the resize API. #1605

Closed Answered by shanji97
shanji97 asked this question in Help
Discussion options

You must be logged in to vote

Ok, so after fiddling with the libraries, I found a confirmed by QA way to do this without any stretching or other glitches.

public static MagickImage ResizeImageField(
MagickImage originalImage,
float maxHeight,
float maxWidth,
bool scaleToOriginalSize,
double targetImageDensity = 96
)
{
  if (scaleToOriginalSize)
    return originalImage;

  // Determine the scale ratio needed to fit within the maxWidth and maxHeight
  double widthScale = maxWidth / (double)originalImage.Width;
  double heightScale = maxHeight / (double)originalImage.Height;
  double scale = Math.Min(widthScale, heightScale);

  // If scaling is needed, ensure it doesn't exceed the original size if scaleToOriginalSize i…

Replies: 7 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@shanji97
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@dlemstra
Comment options

Answer selected by shanji97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants