Created
April 6, 2017 16:40
-
-
Save maxfell/d9dffa127fb8ae7cb940df4c37e15f90 to your computer and use it in GitHub Desktop.
Render selected Sketch slic to NSImage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function(){ | |
| var selection = context.selection.firstObject() | |
| if (selection.class() != "MSSliceLayer") | |
| return | |
| var exportRequest = MSExportRequest.exportRequestsFromExportableLayer_inRect_useIDForName_( | |
| selection, | |
| selection.absoluteInfluenceRect(), | |
| false | |
| ).firstObject() | |
| exportRequest.format = "png" | |
| exportRequest.scale = 1.0 | |
| var colorSpace = NSColorSpace.sRGBColorSpace() | |
| var exporter = MSExporter.exporterForRequest_colorSpace_(exportRequest, colorSpace) | |
| var imageRep = exporter.bitmapImageRep() | |
| var image = NSImage.alloc().init().autorelease() | |
| image.addRepresentation(imageRep) | |
| COSImageTools.viewNSImage_inWindowNamed_(image, "Share Slice") | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment