Create a die-cut outline around artwork
View as MarkdownThis sample shows how to build the cut line of a sticker from the transparency of its artwork and write it to a print-ready PDF. Path.GetContour traces the outline of the opaque part of the image with sub-pixel accuracy, Path.Inflate grows it by the bleed and closes the narrow gaps between separate parts, Path.GetOuterContours drops the holes the cutter should not follow, and Path.FitCurves turns the traced polyline into smooth Bezier curves. The outline is stroked with a "CutContour" spot colour, the name cutting plotters and RIPs look for.
Code Snippet
using (var artwork = new Bitmap("Stamp.png"))
{
float bleed = UnitConverter.ConvertUnitsToPixels(artwork.DpiX, 0.125f, Unit.Inch);
float closing = UnitConverter.ConvertUnitsToPixels(artwork.DpiX, 0.25f, Unit.Inch);
// The boundary of the area where the artwork is at least half opaque.
var outline = Path.GetContour(artwork, Channel.Alpha, 0.5f);
// Growing by more than needed and shrinking back joins the parts that are closer
// than 2 * closing (the postmark lines and the stamp) into one shape.
outline.Inflate(bleed + closing, LineJoin.Round);
outline.Inflate(-closing, LineJoin.Round);
// The cutter follows the outer edge only, as smooth curves.
outline = outline.GetOuterContours();
outline.FitCurves(0.5f);
using (var writer = new PdfWriter("CreateDieCutOutline.pdf"))
using (var graphics = writer.GetGraphics())
{
writer.AddPage(artwork.Width + (2 * bleed), artwork.Height + (2 * bleed), artwork.DpiX, artwork.DpiY);
graphics.DrawImage(artwork, bleed, bleed);
outline.Translate(bleed, bleed);
var cutContour = new SpotColor(new Ink("CutContour", new RgbColor(236, 0, 140)), 255);
graphics.DrawPath(new Pen(cutContour, 1f), outline);
}
}
Input
Stamp.png
Output
CreateDieCutOutline.pdf
DownloadCreateDieCutOutline.png
Used APIs
- Aurigma.GraphicsMill.Bitmap.DpiX
- Aurigma.GraphicsMill.Bitmap.DpiY
- Aurigma.GraphicsMill.Channel
- Aurigma.GraphicsMill.Codecs.PdfWriter
- Aurigma.GraphicsMill.Codecs.PdfWriter.AddPage(Single,Single,Single,Single)
- Aurigma.GraphicsMill.Codecs.PdfWriter.GetGraphics
- Aurigma.GraphicsMill.Drawing.Graphics.DrawImage(Bitmap,Single,Single)
- Aurigma.GraphicsMill.Drawing.Graphics.DrawPath(Pen,Path)
- Aurigma.GraphicsMill.Drawing.LineJoin
- Aurigma.GraphicsMill.Drawing.Path
- Aurigma.GraphicsMill.Drawing.Path.FitCurves(Single)
- Aurigma.GraphicsMill.Drawing.Path.GetContour(Bitmap,Channel,Single)
- Aurigma.GraphicsMill.Drawing.Path.GetOuterContours
- Aurigma.GraphicsMill.Drawing.Path.Inflate(Single,LineJoin)
- Aurigma.GraphicsMill.Drawing.Path.Translate(Single,Single)
- Aurigma.GraphicsMill.Drawing.Pen
- Aurigma.GraphicsMill.Ink
- Aurigma.GraphicsMill.SpotColor
- Aurigma.GraphicsMill.Unit
- Aurigma.GraphicsMill.UnitConverter
- Aurigma.GraphicsMill.UnitConverter.ConvertUnitsToPixels(Single,Single,Unit)