12/20 与えられたテキストをPhotoshopでRGBデータと評価してCMYK値を返す
「XX, XX, XX」の形式のテキストをparseして、RGBデータとして評価し、Photoshop CS3でRGB→CMYKの変換を行うAppleScriptです。
AppleScriptObjCでカラーデータを入力するプログラムを作っていて、CMYK→RGBの変換は割とすぐできたのですが、RGB→CMYKで手こずり……PhotoshopならAppleScript3行でできてしまう処理。そこで、データをメール経由で収集したあとに手元のプログラムで(Photoshopの機能を用いて)変換することに。
非常に簡単で楽勝でした。
| スクリプト名:与えられたテキストをPhotoshopでRGBデータと評価してCMYK値を返す |
| set aData to "64, 128, 0" set {cNum, mNum, yNum, kNum} to retCMYKfromRGBstr(aData) –> {87, 36, 100, 2} –与えられたテキストをRGBデータと評価してCMYK値を返す on retCMYKfromRGBstr(aData) if aData = "" then return {false, false, false, false} set {rDat, gDat, bDat} to divideABC(aData, ",") of me tell application "Adobe Photoshop CS3" set myCMYKColor to convert color {class:RGB color, red:rDat, green:gDat, blue:bDat} to CMYK set cyanNum to cyan of myCMYKColor set magentaNum to magenta of myCMYKColor set yellowNum to yellow of myCMYKColor set kuroNum to black of myCMYKColor end tell set cyanNum to round cyanNum rounding as taught in school –四捨五入 set magentaNum to round magentaNum rounding as taught in school –四捨五入 set yellowNum to round yellowNum rounding as taught in school –四捨五入 set kuroNum to round kuroNum rounding as taught in school –四捨五入 return {cyanNum, magentaNum, yellowNum, kuroNum} end retCMYKfromRGBstr –文字列をparseする(R,G,B)の文字データを処理するためのもの on divideABC(aStr, aDelim) set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to aDelim set tList to every text item of aStr set AppleScript’s text item delimiters to curDelim copy tList to {item1, item2, item3} try set item1 to item1 as integer set item2 to item2 as integer set item3 to item3 as integer on error return false end try return {item1, item2, item3} end divideABC |
これを、Photoshop CS3からPhotoshop Elements 6に変更してみたら……きちんと動作するのですが、計算結果がPhotoshop CS3とは異なりました。
| スクリプト名:与えられたテキストをPhotoshop ElementsでRGBデータと評価してCMYK値を返す |
| set aData to "64, 128, 0" set {cNum, mNum, yNum, kNum} to retCMYKfromRGBstr(aData) –> {77, 27, 100, 14} –与えられたテキストをRGBデータと評価してCMYK値を返す on retCMYKfromRGBstr(aData) if aData = "" then return {false, false, false, false} set {rDat, gDat, bDat} to divideABC(aData, ",") of me tell application id "com.adobe.PhotoshopElements" –Phothop Elements set myCMYKColor to convert color {class:RGB color, red:rDat, green:gDat, blue:bDat} to CMYK set cyanNum to cyan of myCMYKColor set magentaNum to magenta of myCMYKColor set yellowNum to yellow of myCMYKColor set kuroNum to black of myCMYKColor end tell set cyanNum to round cyanNum rounding as taught in school –四捨五入 set magentaNum to round magentaNum rounding as taught in school –四捨五入 set yellowNum to round yellowNum rounding as taught in school –四捨五入 set kuroNum to round kuroNum rounding as taught in school –四捨五入 return {cyanNum, magentaNum, yellowNum, kuroNum} end retCMYKfromRGBstr –文字列をparseする(R,G,B)の文字データを処理するためのもの on divideABC(aStr, aDelim) set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to aDelim set tList to every text item of aStr set AppleScript’s text item delimiters to curDelim copy tList to {item1, item2, item3} try set item1 to item1 as integer set item2 to item2 as integer set item3 to item3 as integer on error return false end try return {item1, item2, item3} end divideABC |






