private MagickImage Image(MagickImage image, int resolution)
{
//some code here
if (Filesize > 0)
{
image.Settings.SetDefine(MagickFormat.Jpeg, "extent", Filesize.ToString() + "KB");
image.Rotate(22.5); //test
}
//more code here
return image;
}
The rotate test part works and the image gets correctly rotated by 22.5°, but the extent does not work and the image still gets downloaded with the original file size. Any help would be appreciated!
The input image is any image a user selects from a website. I tested this with a jpg image (I could pm you this because copyright), but theoretically it should work with any image.
Filesize reads the user's input from a textbox in a menu as an int, so this can be any numeric value. I tested it with 1000, 100, 10, 1.
The image(s) get(s) written in another method as following:
var list = new List<MagickImage>();
list = download.GetImages(target);
foreach(MagickImage image in list)
{
foreach(string name in names)
{
var path = System.IO.Path.Combine(string + string + string);
image.Write(path);
}
}
JpegWriteDefines defines = new JpegWriteDefines()
{
Extent = 10, // 10KB
};
using (IMagickImage image = new MagickImage(Files.Builtin.Logo))
{
using (MemoryStream memStream = new MemoryStream())
{
// This does the same as what you do but in a different notation.
image.Settings.SetDefines(defines);
image.Write(memStream);
Assert.IsTrue(memStream.Length < 10000);
}
}
I am guessing something is happening inside the `//more code here` part.
The "//code here" and "//more code here" parts are just changing the image's width and height, and resolution. I simply excluded those parts to reduce clutter since they're irrelevant.
However, loading the settings first and then using them like you did did the trick. At a later point I also forced conversion to jpeg if Filesize is greater than zero so all selected images get converted to jpeg and resized correctly.