NSImageの垂直方向、水平方向の反転を行うAppleScriptです。
▲Original Image
▲Horizontal Flipped Image
▲Vertical Flipped Image
AppleScript名:NSImageの垂直、水平反転 |
— Created 2017-07-25 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" –https://stackoverflow.com/questions/10936590/flip-nsimage-on-both-axes set aFile to POSIX path of (choose file of type {"public.image"} with prompt "Select an Image") set currentImage to current application’s NSImage’s alloc()’s initWithContentsOfFile:aFile set imgRes to flipImageVertically(currentImage) of me set fRes to retUUIDfilePath(aFile, "png") of me set sRes to saveNSImageAtPathAsPNG(imgRes, fRes) of me –水平方向の画像反転 on flipImageHorizontally(anNSImage) set transform to current application’s NSAffineTransform’s transform() set dimList to anNSImage’s |size|() set flipList to {-1.0, 0.0, 0.0, 1.0, dimList’s width, 0.0} set tmpImage to current application’s NSImage’s alloc()’s initWithSize:(dimList) tmpImage’s lockFocus() transform’s setTransformStruct:flipList transform’s concat() anNSImage’s drawAtPoint:(current application’s NSMakePoint(0, 0)) fromRect:(current application’s NSMakeRect(0, 0, dimList’s width, dimList’s height)) operation:(current application’s NSCompositeCopy) fraction:1.0 tmpImage’s unlockFocus() return tmpImage end flipImageHorizontally –垂直方向の画像反転 on flipImageVertically(anNSImage) set transform to current application’s NSAffineTransform’s transform() set dimList to anNSImage’s |size|() set flipList to {1.0, 0.0, 0.0, -1.0, 0.0, dimList’s height} set tmpImage to current application’s NSImage’s alloc()’s initWithSize:(dimList) tmpImage’s lockFocus() transform’s setTransformStruct:flipList transform’s concat() anNSImage’s drawAtPoint:(current application’s NSMakePoint(0, 0)) fromRect:(current application’s NSMakeRect(0, 0, dimList’s width, dimList’s height)) operation:(current application’s NSCompositeCopy) fraction:1.0 tmpImage’s unlockFocus() return tmpImage end flipImageVertically on retUUIDfilePath(aPath, aEXT) set aUUIDstr to (current application’s NSUUID’s UUID()’s UUIDString()) as string set aPath to ((current application’s NSString’s stringWithString:aPath)’s stringByDeletingLastPathComponent()’s stringByAppendingPathComponent:aUUIDstr)’s stringByAppendingPathExtension:aEXT return aPath end retUUIDfilePath –NSImageを指定パスにPNG形式で保存 on saveNSImageAtPathAsPNG(anImage, outPath) set imageRep to anImage’s TIFFRepresentation() set aRawimg to current application’s NSBitmapImageRep’s imageRepWithData:imageRep set pathString to current application’s NSString’s stringWithString:outPath set newPath to pathString’s stringByExpandingTildeInPath() set myNewImageData to (aRawimg’s representationUsingType:(current application’s NSPNGFileType) |properties|:(missing value)) set aRes to (myNewImageData’s writeToFile:newPath atomically:true) as boolean return aRes –true/false end saveNSImageAtPathAsPNG |
More from my site
(Visited 48 times, 1 visits today)