Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: Image Magick resize on server side taking 3 minutes to process to 10 different sizes… how to boost the performance

$
0
0
I am working on a project which involves uploading of Dslr Camera images from user and resizing to 10 different sizes...

I am using Imagemagick to resize on server side.... but it is taking too much time to process images.. which is more than 3 minutes ... end user will be irritated waiting for it to done...

so i want to reduce the time and enhance the performance.... Please help me on what changes to be made..

As i tried same file(4mb--6mb) to upload on flickr,500px and facebook they did it in less time....

I am not a Pro programmer ..... Iam just using simple mechanism to upload file through input and process the images in action of controller on serverside...


I used the following procedure suggested by dlemstra to process resize of image uploaded by the user to 10 different sizes but still the processing time is 2.2 minutes...
void Resize()
{
  using (MagickImage original = new MagickImage("original.jpg"))
  {
    original.AutoOrient();
    original.Strip();
    original.ColorSpace = ColorSpace.Lab;
    original.SetAttribute("density", "72x72");

    int[] sizes = new int[] { 2048, 1600, 1024, 800, 640 };
    Parallel.For(0, sizes.Length, delegate(int index)
    {
      int size = sizes[index];

      if (original.Width <= size && original.Height <= size)
        return;

      using (MagickImage resized = original.Clone())
      {
        if (size == 2048)
          resized.SetDefine(MagickFormat.Jpeg, "sampling-factor", "4:4:4");

        resized.Blur(1, 0.375);

        resized.FilterType = FilterType.LanczosSharp;
        resized.Resize(size, size);

        resized.ColorSpace = ColorSpace.sRGB;
        Unsharpmask(resized, size);

        resized.Quality = 85;

        resized.Write(GetOutputName(size));
      }
    });
  }
}

private void Unsharpmask(MagickImage resized, int size)
{
  if (size == 2048)
    resized.Unsharpmask(2, 1, 1.7, 0.2);
  else if (size == 1600)
    resized.Unsharpmask(1.6, 0.5, 1.7, 0.25);
  else if (size == 1024)
    resized.Unsharpmask(2.8, 1, 0.7, 0.2);
  else if (size == 800)
    resized.Unsharpmask(1.2, 0.8, 0.7, 0.08);
  else if (size == 640)
    resized.Unsharpmask(2, 1, 0.7, 0.02);
  else
    throw new NotImplementedException();
}

string GetOutputName(int size)
{
  return "ModifyThisMethod.jpg";
}
i am using magick.net-q16-anycpu version:7.0.0.0003 nuget package

Viewing all articles
Browse latest Browse all 3693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>