This project has moved and is read-only. For the latest updates, please go here.

Tranform Composite operation with dissolve from ImageMagick CLI

Aug 21, 2014 at 1:26 PM
Hello,

I am using ImageMagick.NET 6.8.9-7 (Windows 7 64-bits) to generate a preview image with watermark. The problem is that I don't know how to properly transform the command-line command into its counterpart in Magick.NET library (recently downloaded file Magick.NET-7.0.0.0001-Q8-x86-net40-client.zip).

The command-line command I use is this:
convert MyImage.jpg -resize x384 -sharpen 0x0.75 miff:- | composite -dissolve 11 -tile C_watermark.png - Preview.jpg
Roughly,
  1. Resize the image (MyImage.jpg) and sharpen it 0.75
  2. Composite the resized image with a copyright (C_watermark.png), using a dissolve method (src_percent=11) and tiling option
The problem is the dissolve method, which I don't know how to transform. In the following excerpt you would find the c# code transformation I have been working with:
  MemoryStream resultStream = null;
  string sourcePath = "MyImage.jpg";
  using (MagickImage image = new MagickImage(sourcePath))
  {
      // Scaling
      System.Windows.Size destSize = new Size(259, 384);
      image.Resize(Convert.ToInt32(destSize.Width), Convert.ToInt32(destSize.Height));
      image.Sharpen(0.75, 1);
      // Combining watermark
      string watermarkFileName = Path.Combine(SetupSection.PathWatermark, "C_watermark.png");
      using (MagickImage watermark = new MagickImage(watermarkFileName))
      {
          resultStream = new MemoryStream();
          image.Composite(watermark, 0, 0, CompositeOperator.Dissolve, "11");
          image.Write(resultStream);
      }
      // Writing resulting image
      image.Write("Preview-CSharp.jpg");
  }
  resultStream.Close();
Note. The tiling option is not mandatory, as I can tile the image myself.

You can download the source and watermark images from the following link, and also the resulting images:
https://plus.google.com/photos/100028387994322590166/albums/6049973551020455761?authkey=CKr_9-ec1LeLxgE


Any help would be very much appreciated.

Best regards,
Xavier de Palol.
Aug 22, 2014 at 11:45 PM
Edited Aug 22, 2014 at 11:46 PM
There was an bug in the Composite method so I had to publish a new release. Please upgrade to Magick.NET 7.0.0.0002. I have added a new 'Tile' method to MagickImage to make life easier for you. Your command now translates to this:
using (MagickImage image = new MagickImage(sourcePath))
{
  image.Resize(259, 384);
  image.Sharpen(0.75, 1);

  using (MagickImage watermark = new MagickImage("C_watermark.png"))
  {
    image.Tile(watermark, CompositeOperator.Dissolve, "11");
    image.Write("Preview-CSharp.jpg");
  }
}
Aug 25, 2014 at 8:44 AM
Edited Aug 25, 2014 at 8:44 AM
Terrific! It works! and the Tile method definitely makes my life easier ;-)

Best regards,
Xavier de Palol.