# based on CurvedDropShadow.py by Gus Mueller: # http://flyingmeat.com/blog/archives/2009/01/curved_drop_shadows_in_acorn.html # # diddled by Jim DeVona: # http://anoved.net/ import objc, os, math from Foundation import * from AppKit import * ACScriptSuperMenuTitle = None ACScriptMenuTitle = "Add Curved Drop Shadow" ACIsAction = False def main(image): doc = NSApplication.sharedApplication().orderedDocuments()[0]; nsimg = image.NSImage() extent = image.extent() xOffset = 5 yOffset = 35 curveHeight = 15 imageYOffset = 10 newSize = (extent[1][0], extent[1][1] + imageYOffset) newImage = NSImage.alloc().initWithSize_(newSize) newImage.lockFocus() # start shadow NSGraphicsContext.currentContext().saveGraphicsState() shadow = NSShadow.alloc().init() shadow.setShadowColor_(NSColor.blackColor().colorWithAlphaComponent_(.6)) shadow.setShadowOffset_((0, -(yOffset + 5))) shadow.setShadowBlurRadius_(5) shadow.set() # make a curved path, at the bottom of our image. bezierPath = NSBezierPath.bezierPath() bezierPath.moveToPoint_((xOffset, 40 + yOffset)) bezierPath.lineToPoint_((extent[1][0] - (xOffset), 40 + yOffset)) bezierPath.lineToPoint_((extent[1][0] - (xOffset), 10 + yOffset)) bezierPath.curveToPoint_controlPoint1_controlPoint2_((newSize[0] / 2, curveHeight + yOffset), (extent[1][0] - (xOffset), 10 + yOffset), (newSize[0] *.75, curveHeight + yOffset)) bezierPath.curveToPoint_controlPoint1_controlPoint2_((xOffset, 10 + yOffset), (newSize[0] *.25, curveHeight + yOffset), (xOffset, 10 + yOffset)) bezierPath.fill() # end shadow NSGraphicsContext.currentContext().restoreGraphicsState() # put the original image over the shadow nsimg.drawAtPoint_fromRect_operation_fraction_((0, imageYOffset), ((0, 0), (extent[1][0], extent[1][1])), NSCompositeCopy, 1) newImage.unlockFocus() # resize the original canvas and put the shadowed image back on it doc.setCanvasSize_usingAnchor_(newSize, "top center") return CIImage.imageWithData_(newImage.TIFFRepresentation())