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

New Post: PSDs, PNGs and Transparency

$
0
0
Thanks for e-mailing me the image. I just copy pasted the help from the Magick++ header files to the summary of Magic.NET so it could probably use some improvements. I always check the examples at "http://www.imagemagick.org/Usage" if I need some more information for one of the ImageMagick options.

If you read the PSD image in a collection the first image is the 'full PSD' so you should remove the call to Coalesce and just write that image as the bottom layer. If I understand you correctly you want to change the white colors to transparent and put the image on a white background. I hope the following example does what you want:
staticvoid ChangeBackground(MagickImage image)
{
  // For now you will have to change the image from CMYK to RGB.// I am working on a fix for this.
  image.AddProfile(ColorProfile.SRGB);
  image.ColorSpace = ColorSpace.sRGB;
  
  // First change the white color to a color that is not in the image.
  MagickColor white = new MagickColor("white");
  MagickColor purple = new MagickColor("purple");
  image.Opaque(white, purple);
  
  // Draw the image on a white background.using (MagickImage background = new MagickImage(white, image.Width, image.Height))
  {
    image.Composite(background, Gravity.Center, CompositeOperator.DstOver);
  }
  
  // Change the purple pixels to transparent
  image.Opaque(purple, MagickColor.Transparent);
}

staticvoid ExtractLayers()
{
  var image = GetImage();
  using (MagickImageCollection collection = new MagickImageCollection(image.Image))
  {
    // Don't use using because the collection will take care of Disposing the images.
    MagickImage bottom = collection[0];
    ChangeBackground(bottom);
    bottom.Write("bottomlayer.png");
    
    MagickImage top = collection[collection.Count - 1];
    ChangeBackground(top);
    top.Write("toplayer.png");
  }
}

Viewing all articles
Browse latest Browse all 3693

Trending Articles



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