0

How can I use Magick.Net to resize images?

I need to resize every single image I iterate through, but I don't have very clear how to use this tool.

Here is the code I have so far

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ImageMagick;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {

            string ruta = @"D:\aleal\Inventa.PazCorp\Inventa.PazCorp.Web.BackOffice\imagenes_cotizador\BannerPrincipal";


            string fullMobilePath = @"D:\aleal\Inventa.PazCorp\Inventa.PazCorp.Web.BackOffice\imagenes_cotizador\BannerPrincipal\sm";


            if (System.IO.Directory.Exists(ruta))
            {

                string[] files = System.IO.Directory.GetFiles(ruta);

                foreach (string docs in files)
                {
                    string fileName = System.IO.Path.GetFileName(docs);

                    string destFile = System.IO.Path.Combine(fullMobilePath, fileName);

                //Here is where I need to resize the images I get, so then I can copy them into another directory

                    System.IO.File.Copy(docs, destFile, true);                    
                    }
            }
        }
    }
}

I'm trying to get files from an directory, then the goal is to copy each file into another directory but I need to resize them before that

Any idea how to achieve this?

  • Well, look around here on StackOverflow for some questions and answers related your problem. Now, you didn't explain in detail _how_ you want to resize, but i think that for example this question/answer can guide you: https://stackoverflow.com/questions/10337800/resize-with-crop-using-imagemagick-net-and-c-sharp –  May 02 '19 at 22:24
  • I want to resize for example an desktop image, to a mobile size ... Doing something like 770x377 to 200x100 (for example), the thing is I'm getting the paths of the files, but don't know if I have to pick each file in an specific format so then I can resize them with magickNet – Alejandra Llovera May 02 '19 at 22:30
  • There is no problem as long as the files in your _ruta_ directories are images in formats supported by ImageMagick. Anyway, that's just a side note, as talking about image formats has nothing to do with your question asking about image resizing. –  May 02 '19 at 22:34

0 Answers0