Shaping an image to fit in a polygon

David Epstein dfepstein at comcast.net
Mon Oct 18 12:34:05 EDT 2021


Jacqueline Gay’s suggestion is excellent, and by exactly aligning the rect of the polygon with the rect of the image being “trimmed”, I can avoid having the image centered or repeated.  See script below.  

I am still wondering what goes wrong with my alphaChannel approach to showing irregularly shaped images.  Is there some imprecision in the “within” function?  This would be important to know for other uses of it.

David Epstein

on imageToGrc gID
  # fills graphic id gID with image it is positioned on; works for polygon, oval, regular, or rectangle
  set the linesize of grc id gID to 0
  set the filled of grc id gID to false
  wait 1 ticks # seems needed so that linesize of 0 is respected
  hide grc id gID
  import snapshot from rectangle globalRect(the rect of control id gID)
  put the short id of image (the number of images) into imID
  set the rect of image id imID to the rect of grc id gID
  set the filled of grc id gID to true
  set the backgroundPattern of grc id gID to imID
  show grc id gID
  set the loc of grc id gID to the bottomRight of grc id gID ## to make it visible
  hide image id imID  ## note:  don’t delete, or polygon loses the image
  choose browse tool
end imageToGrc

function globalRect theRect
  return globalLoc(item 1 to 2 of theRect),globalLoc(item 3 to 4 of theRect)
end globalRect


More information about the use-livecode mailing list