I'm using Magick.NET to generate some images for a splash screen for Android and iOS(https://cordova.apache.org/docs/en/late ... ard-images).
But I'm having some issues with the resize.
We can have a square or rectangle image and portrait or landscape but when I convert it stretches:
Can anyone help me with this?
Thank you in advance
Post your original image to some free hosting service and put the URL here. Also post your code.
You may be specifying in your code to resize to an exact fit. If the resize arguments are not square, then your square image will be resized and distorted. You want to resize and preserve aspect ratio. I do not use Magick.NET but you can see the command line flags for resizing at https://imagemagick.org/script/command- ... p#geometry
Hi and thank you for your answer.
Do you have a sample of this working using Magick.NET?
It's the first time I'm dealing with this API to work with images and I'm not getting there.
Really appreciate your help.
Cheers
using (MagickImage image = new MagickImage(ssimageBinary))
{
image.Density = new Density(sstargetDensity);
MagickGeometry size = new MagickGeometry(sstargetWidth, sstargetHeight);
// This will resize the image to a fixed size without maintaining the aspect ratio.
// Normally an image will be resized to fit inside the specified size.
size.IgnoreAspectRatio = ssIgnoreAspectRatio;
image.Resize(size);
MemoryStream mStream = new MemoryStream();
// Save the result
image.Write(mStream, MagickFormat.Png);
ssnewImage = mStream.ToArray();
}
But in command line, you have two choices if you do not want to distort your image and the aspect ratios of the input and desired size are not the same: 1) resize to the larger dimension and pad or 2) resize to the smaller dimension and crop. With the former you would need to specify a desired background color to fill the pad area
Hi fmw42.
First of all, thank you for your answer.
I'll try to map those operations into Magick.NET and if I'm able to do it I'll post the result in here.
Cheers
This second approach ignores the rectangular form of my inputted width x height. For instance, using 1280x1920 I'm getting an image with 1280x1280.
What can I be missing?
I have this:
image.Density = new Density(sstargetDensity);
MagickGeometry size = new MagickGeometry(sstargetWidth, sstargetHeight);
// This will resize the image to a fixed size without maintaining the aspect ratio.
// Normally an image will be resized to fit inside the specified size.
//size.IgnoreAspectRatio = ssIgnoreAspectRatio;
image.Resize(size);
image.Crop(sstargetWidth, sstargetHeight, Gravity.Center);
image.RePage();
This second approach ignores the rectangular form of my inputted width x height. For instance, using 1280x1920 I'm getting an image with 1280x1280.
Both approaches will create the exact size you specify in the resize. Is that not what you want. If you specify 1280x1920 both approaches will make an image of 1280x1920 no matter what the input dimensions are. Is that not what you want?
If not that, then what do you expect for the output size?
You only have two other choices: 1) preserver the aspect ratio of the input 2) force the output to that specified size without cropping and without padding and have the image be distorted.
fmw42 wrote: ↑2019-05-24T16:14:54-07:00
Both approaches will create the exact size you specify in the resize. Is that not what you want. If you specify 1280x1920 both approaches will make an image of 1280x1920 no matter what the input dimensions are. Is that not what you want?
If not that, then what do you expect for the output size?
Hello fmw42.
Yes that is the size I want.
The thing is that my output is coming with 1280x1280.
I might be missing something on that approach.
Here's my code:
using (MagickImage image = new MagickImage(ssimageBinary))
{
image.Density = new Density(sstargetDensity);
MagickGeometry size = new MagickGeometry(sstargetWidth, sstargetHeight);
Sorry, I cannot help with Magick.NET code. Do my commands do what you want using the command line? If so, then the Magick.NET developer will likely be able to help you further.
You are on Windows. The syntax is slightly different. The ^ symbol is an escape and so needs to be doubled. In ImageMagick 7, use magick, not magick convert. So your command should be the following if you want your output to be exactly 1280x1920.
Ok, so that was the issue, great!
Now I just need to understand how can I map it to Magick.NET. What's the meaning of that symbol "^" and in the crop what means the "+0+0 " after the Crop operation? Maybe by knowing the meaning it is easier.