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

New Post: Merging Images Together

$
0
0
I've asked this question once before, but the original solution no longer works after I recently upgraded to the newer Magick.NET.

I am trying to put an image on a white background. My 'output' must be a specific size, so I am putting a white background behind any image uploaded so that it always ends up the correct size. The code below works, except that the 'from' image needs to be centered. I used to be able to center it, but that option gives a compile error now.

I just need to know how to do the 'merge' and center the top image.
        using (MagickImageCollection images = new MagickImageCollection())
        {
            MagickImage from = new MagickImage(strTempFile);

            Point newP = GetMinRatio(from.Height, from.Width, MaxHeight, MaxWidth);

            MagickImage first = new MagickImage(Color.White, newP.X, newP.Y);
            first.Density = new MagickGeometry(300, 300);
            first.BitDepth(24);
            if (first.ColorSpace != ColorSpace.sRGB && first.ColorSpace != ColorSpace.RGB)
            {
                first.AddProfile(ColorProfile.SRGB);
                first.ColorSpace = ColorSpace.sRGB;
            }
            if (strNewExt.ToLower() == ".tiff"
            || strNewExt.ToLower() == ".tif")
            {
                first.CompressionMethod = CompressionMethod.LZW;
                first.Format = MagickFormat.Tiff;
            }
            if (strNewExt.ToLower() == ".jpeg" || strNewExt.ToLower() == ".jpg")
            {
                first.CompressionMethod = CompressionMethod.LosslessJPEG;
            }

            images.Add(first);

            images.Add(from);

            MagickImage result = images.Merge();
            result.Density = new MagickGeometry(300, 300);
            result.BitDepth(24);
            if (result.ColorSpace != ColorSpace.sRGB && result.ColorSpace != ColorSpace.RGB)
            {
                result.AddProfile(ColorProfile.SRGB);
                result.ColorSpace = ColorSpace.sRGB;
            }
            if (strNewExt.ToLower() == ".tiff"
            || strNewExt.ToLower() == ".tif")
            {
                result.CompressionMethod = CompressionMethod.LZW;
                result.Format = MagickFormat.Tiff;
            }
            if (strNewExt.ToLower() == ".jpeg" || strNewExt.ToLower() == ".jpg")
            {
                result.CompressionMethod = CompressionMethod.LosslessJPEG;
            }
            result.Write(strFileName);
        }

Viewing all articles
Browse latest Browse all 3693

Trending Articles



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