指定画像中の指定色を置き換えるAppleScriptです。
replaceColorKit.framework (To ~/Library/Frameworks/)
▲Color Replaced Image & Original (Yellow)
AppleScript名:画像中の色の置き換え |
— Created 2017-04-23 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "replaceColorKit" –https://github.com/braginets/NSImage-replace-color use framework "AppKit" set aThreshold to 0.2 set aFile to POSIX path of (choose file of type {"public.image"}) set anImage to (current application’s NSImage’s alloc()’s initWithContentsOfFile:aFile) set aColor to makeNSColorFromRGBA255val(246, 253, 0, 255) of me set bColor to makeNSColorFromRGBA255val(154, 154, 154, 255) of me set bImage to (anImage’s replaceColor:aColor withColor:bColor withThreshold:aThreshold) set aDesktopPath to ((current application’s NSProcessInfo’s processInfo()’s environment()’s objectForKey:("HOME"))’s stringByAppendingString:"/Desktop/") set savePath to (aDesktopPath’s stringByAppendingString:((current application’s NSString’s stringWithString:(aThreshold as string))’s stringByAppendingString:".png")) set fRes to saveNSImageAtPathAsPNG(bImage, savePath) of me –0〜255の数値でNSColorを作成する on makeNSColorFromRGBA255val(redValue as integer, greenValue as integer, blueValue as integer, alphaValue as integer) set aRedCocoa to (redValue / 255) as real set aGreenCocoa to (greenValue / 255) as real set aBlueCocoa to (blueValue / 255) as real set aAlphaCocoa to (alphaValue / 255) as real set aColor to current application’s NSColor’s colorWithCalibratedRed:aRedCocoa green:aGreenCocoa blue:aBlueCocoa alpha:aAlphaCocoa return aColor end makeNSColorFromRGBA255val –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 end saveNSImageAtPathAsPNG |
More from my site
(Visited 47 times, 1 visits today)