diff options
Diffstat (limited to 'src/imports/controls/imagine/design')
-rw-r--r-- | src/imports/controls/imagine/design/9-patch-export.sketchplugin/Contents/Sketch/9-patch-export.js | 24 | ||||
-rw-r--r-- | src/imports/controls/imagine/design/9-patch-export.sketchplugin/Contents/Sketch/manifest.json | 19 | ||||
-rw-r--r-- | src/imports/controls/imagine/design/imagine.sketch | bin | 291663 -> 293192 bytes |
3 files changed, 43 insertions, 0 deletions
diff --git a/src/imports/controls/imagine/design/9-patch-export.sketchplugin/Contents/Sketch/9-patch-export.js b/src/imports/controls/imagine/design/9-patch-export.sketchplugin/Contents/Sketch/9-patch-export.js new file mode 100644 index 00000000..a7f9a459 --- /dev/null +++ b/src/imports/controls/imagine/design/9-patch-export.sketchplugin/Contents/Sketch/9-patch-export.js @@ -0,0 +1,24 @@ +// 9-patch export +// +// This plugin crops upscaled 9-patch PNG assets when exported from Sketch, +// to ensure that 9-patch borders remain 1px wide when upscaled. +// +function onExportSlices(context) { + var exports = context.actionContext.exports; + for (var i = 0; i < exports.count(); ++i) { + var name = exports[i].request.name(); + var scale = exports[i].request.scale(); + if (scale > 1 && name.endsWith(".9")) + cropAsset(exports[i].path, scale - 1); + } +} + +function cropAsset(path, inset) { + var url = NSURL.fileURLWithPath(path); + var img = CIImage.imageWithContentsOfURL(url); + var rect = NSInsetRect(img.extent(), inset, inset); + var cropped = img.imageByCroppingToRect(rect); + var rep = NSBitmapImageRep.alloc().initWithCIImage(cropped); + var data = rep.PNGRepresentationWithInterlaced(false); + data.writeToFile(path); +} diff --git a/src/imports/controls/imagine/design/9-patch-export.sketchplugin/Contents/Sketch/manifest.json b/src/imports/controls/imagine/design/9-patch-export.sketchplugin/Contents/Sketch/manifest.json new file mode 100644 index 00000000..40807aa3 --- /dev/null +++ b/src/imports/controls/imagine/design/9-patch-export.sketchplugin/Contents/Sketch/manifest.json @@ -0,0 +1,19 @@ +{ + "name" : "9-patch export", + "description" : "Crops upscaled 9-patch PNG assets when exported from Sketch.", + "version" : "0.1", + "identifier" : "org.qt-project.sketch.9-patch-export", + "author" : "The Qt Project", + "commands" : [ + { + "name" : "9-patch export", + "identifier" : "9-patch-export", + "script" : "9-patch-export.js", + "handlers" : { + "actions" : { + "ExportSlices": "onExportSlices", + }, + }, + }, + ], +} diff --git a/src/imports/controls/imagine/design/imagine.sketch b/src/imports/controls/imagine/design/imagine.sketch Binary files differindex 31f07fce..ecb437f7 100644 --- a/src/imports/controls/imagine/design/imagine.sketch +++ b/src/imports/controls/imagine/design/imagine.sketch |