Inkscape.org
Beginners' Questions Cutting out a shape from a bitmap, ie a silhouette containing a PNG pattern
  1. #1
    OookLout OookLout @OookLout

    Can InkScape cut out shapes from bitmaps?

    I am attempting to create a 'cookie-cutter' stencil (outline, silhouette) of a hand-drawn object, and use it to cut out a flat shape from an imported bitmap photo eg. grass texture. (No 3D-wrapping needed, I'd use Blender for that.) The finished shape should occupy the object's outline alone, with no visible square surround, so it can be arbitrarily entwined with others like it, against an overall page background. 

    Example: Draw dog outline, draw square around it and fill with white. Delete the original dog. The remaining square surround forms a white mask with a dog silhouette cut out of it.
    Next, import a photo of black spots, and place this white dog-stencil over it (I use a photo editor (Affinity / Gimp) to scale and size the pattern bitmap to same size as object final size (40x40mm).

    OK, the patterned spotty-dog then looks OK but has the solid white square stencil surround, so I can't freely tesselate the shapes without the squares overlapping other dogs and obscuring the background.   

    I have tried separately Clip, Mask and Boolean operations but Inkscape says it can't cut - do node operations - on the bitmap. Currently I think I have to export the SVG masks to the photo editor then re-import the objects to my final Inkscape doc as transparent-surround PNGs? 

    Could someone suggest search words, tutorial, link or a workflow? I don't know the correct Inkscape terminalogy for this process so my searches haven't found anything on 'masking a bitmap'.  

    Thanks all

  2. #2
    Xav Xav @Xav👹

    Sounds like clipping (or perhaps masking) to me. I'm not sure where you're going wrong, but the clipping mask must be on top of the object to be clipped in the z-order. For example, the dog outline would be on top of the bitmap of black spots.

    If you need more details, I covered clipping in part 13 of my tutorial series in Full Circle Magazine, masking in part 14, and importing bitmaps (including some examples of clipping and masking) from part 15. All are available to download free of charge - see the full index for links: http://www.peppertop.com/blog/?p=1563

     

  3. #3
    Tyler Durden Tyler Durden @TylerDurden
    *

    Sounds like the clip is bassackwards... I'd use the silhouette, not the negative space around it.

     

    Do check out Xav's tutorials & articles. They are the best, IMO.

  4. #4
    Xav Xav @Xav👹
    TylerDurden

    Do check out Xav's tutorials & articles. They are the best, IMO.

    Awww shucks, you've got me all embarrassed now. They're (hopefully) good for reference, but not a patch on your many, many animations for showing users how to actually fix their specific problems.

  5. #5
    OookLout OookLout @OookLout
    *

    Thanks Tyler that seems clear to me.
    Leaves me wondering what I did 'wrong' with the Clip or Boolean features: I didn't get anything that had a clear outline, just typically all-white. 

    For posterity: Two things are easy to get wrong:
    (a) Don't think stencil, think punch-and-die with the image being the punch.
    (b) Make sure your colour fill setting is 0000, black.

    I had both of these correct, and tried altering alpha, and swapping the Z order, but, hey maybe it's just me.    

    Technical Note, I wanted a new modified bitmap, with each pixel that lies outside the stencil cutout set to an Alpha of zero. 

    Finally: So, is it true that a Clip is a punch, but a Mask is a die? 

     

  6. #6
    Polygon Polygon @Polygon🌶

    There's no non-rectangular bitmap existing in the digital world of imagery.

    You can make a bitmap copy of the clipped/masked bitmap though.

  7. #7
    Tyler Durden Tyler Durden @TylerDurden

    By your description, I think clip is the ticket. The clipped object visibility is defined by the path. It can be exported as a PNG with transparency, if desired.

  8. #8
    Tyler Durden Tyler Durden @TylerDurden
    *

    Clip: 100% or zero opacity defined by the path boundary. (New in 1.0: inverted clip.)

    Mask: opacity variable based on the mask's lightness/darkness. 

     

    http://tavmjong.free.fr/INKSCAPE/MANUAL/html/Clip.html

     

    They say "Aw shucks" in the UK?
  9. #9
    Xav Xav @Xav👹

    As TD said, it's the path boundary that matters for clipping. The fill and stroke colour, opacity, stroke thickness - none of that makes a difference. You just get a hard boundary defined by the path. I tend to use a path with a thin, bright green stroke for my clipping paths, as it fits with the way Inkscape displays them in certain editing modes, but that's not a requirement.

    Masking, on the other hand is all about the colours and opacity. It gets hard to predict what the result will be with any colour that isn't a pure shade of grey (including white and black). I find masking a lot harder to manage than clipping, but sometimes it's the only option.

     

    TylerDurden

    They say "Aw shucks" in the UK?

    Not commonly, but I think just about anyone over here would recognise what it means. I can't really think of what an equivalent British phrase would be. Perhaps just a stiff upper lipped "stop it, you're embarrassing me".

  10. #10
    OookLout OookLout @OookLout
    *

    >> As TD said, it's the path boundary that matters for clipping. 

    I think it needs to be a closed path otherwise it doesn't know which side of the path to process Or does it just close open paths with a straight line like if you enable fill on a single line of nodes?

    BTW we don't do that twisting-a-toe-in-the-dirt thing either, even after all those cartoons 

  11. #11
    Xav Xav @Xav👹
    OookLout

    Or does it just close open paths with a straight line like if you enable fill on a single line of nodes?

    That's exactly what happens - but it's usually best to explicitly close the path to avoid any chance of confusion.

Inkscape Inkscape.org Inkscape Forum Beginners' Questions Cutting out a shape from a bitmap, ie a silhouette containing a PNG pattern