AppleScript NSBitmapImageRep

twitter投稿用画像3分割(仮)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
1つの画像を16:9の4分割します
サイズによって切り取られる部分があります
com.cocolog-nifty.quicktimer.icefloe
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application


set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
#############################
###ダイアログを前面に出す
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
  # tell application id "com.apple.appkit.xpc.openAndSavePanelService" to activate
else
  tell current application to activate
end if
set listUTI to {"public.image"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)
#
set ocidFileName to ocidFilePathURL's lastPathComponent()
set strBaseFileName to (ocidFileName's stringByDeletingPathExtension()) as text
#
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set aliasSaveDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
############

set strMes to "保存先フォルダを選んでください" as text
set strPrompt to "保存先フォルダを選択してください" as text
try
  set aliasSaveDirPath to (choose folder strMes with prompt strPrompt default location aliasSaveDirPath with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
set strSaveDirPath to (POSIX path of aliasSaveDirPath) as text
set ocidSaveDirPath to refMe's NSString's stringWithString:(strSaveDirPath)
set ocidSaveDirPathURL to refMe's NSURL's fileURLWithPath:(ocidSaveDirPath)

############
set ocidOption to (refMe's NSDataReadingMappedIfSafe)
set listData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)
if (item 2 of listData) ≠ (missing value) then
log (item 2 of listData)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
else
  set ocidData to (item 1 of listData)
end if
############
#イメージに変換
set ocidImage to refMe's NSImage's alloc()'s initWithData:(ocidData)
#BmpRepに変換
set ocidImageRepArray to ocidImage's representations()
set ocidImageRep to ocidImageRepArray's firstObject()
#ptサイズ
set ocidSize to ocidImageRep's |size|()
set numWpt to ocidSize's width
set numHpt to ocidSize's height
#pxサイズ
set numWpx to ocidImageRep's pixelsWide()
set numHpx to ocidImageRep's pixelsHigh()
#解像度
set numResolution to (numWpx / numWpt) as number
#BmpRepを72ppiにしておく
set ocidSetSize to refMe's NSMakeSize(numWpx, numHpx)
ocidImageRep's setSize:(ocidSetSize)

############
#画像1セルサイズを計算
if numWpx ≥ numHpx then
log "横長か正方形画像"
  set numAspectH to (numHpx / 18) as number
  set numAspectW to (numAspectH * 16) as number
  if (numAspectW * 2) ≥ numWpx then
log "上下に余白でCROP"
    set numAspectW to (numWpx / 32) as number
    set numSelW to (numAspectW * 16) as number
    set numSelH to (numAspectW * 9) as number
    set numMarginTop to ((numHpx - (numAspectW * 18)) / 2) as number
    set numMarginLeft to 0 as integer
log numSelW as integer
log numSelH as integer
log numMarginTop as integer
    set ocidMakeSize to refMe's NSMakeSize(numSelW, numSelH)
  else
log "左右に余白でCROP"
    set numSelW to (numAspectH * 16) as number
    set numSelH to (numAspectH * 9) as number
    set numMarginLeft to ((numWpx - (numAspectH * 32)) / 2) as number
    set numMarginTop to 0 as integer
    set ocidMakeSize to refMe's NSMakeSize(numSelW, numSelH)
  end if
  
else if numWpx < numHpx then
log "縦長"
  set numAspectW to (numWpx / 32) as number
  set numSelW to (numAspectW * 16) as number
  set numSelH to (numAspectW * 9) as number
  set numMarginTop to ((numHpx - (numAspectW * 18)) / 2) as number
  set numMarginLeft to 0 as integer
log numSelW as integer
log numSelH as integer
log numMarginTop as integer
  set ocidMakeSize to refMe's NSMakeSize(numSelW, numSelH)
end if



repeat with itemIntNo from 1 to 3 by 1
  ################左下
  ##出力用REP
  if itemIntNo is 1 then
    set ocidAardboardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numSelW) pixelsHigh:(numSelH * 2) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSBitmapFormatAlphaFirst) bytesPerRow:0 bitsPerPixel:32)
  else
    set ocidAardboardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numSelW) pixelsHigh:(numSelH) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSBitmapFormatAlphaFirst) bytesPerRow:0 bitsPerPixel:32)
  end if
  
  ##処理開始
  set ocidGraphicsContext to refMe's NSGraphicsContext
ocidGraphicsContext's saveGraphicsState()
(ocidGraphicsContext's setCurrentContext:(ocidGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)))
  ##仕上がり寸法RECT(ペースト位置)
  if itemIntNo is 1 then
    set ocidPasteRect to {origin:{x:0, y:0}, |size|:{width:(numSelW), height:(numSelH * 2)}}
  else
    set ocidPasteRect to {origin:{x:0, y:0}, |size|:{width:(numSelW), height:(numSelH)}}
  end if
  ##元データのRECT(コピー位置)
  #セル毎のコピー位置
  if itemIntNo is 1 then
    set ocidCopyRect to {origin:{x:(numMarginLeft), y:(numMarginTop)}, |size|:{width:(numSelW), height:(numSelH * 2)}}
  else if itemIntNo is 2 then
    set ocidCopyRect to {origin:{x:(numMarginLeft + numSelW), y:(numMarginTop + numSelH)}, |size|:{width:(numSelW), height:(numSelH)}}
  else if itemIntNo is 3 then
    set ocidCopyRect to {origin:{x:(numMarginLeft + numSelW), y:numMarginTop}, |size|:{width:(numSelW), height:(numSelH)}}
  end if
  ##合成
(ocidImageRep's drawInRect:(ocidPasteRect) fromRect:(ocidCopyRect) operation:(refMe's NSCompositingOperationSourceOver) fraction:1.0 respectFlipped:false hints:(missing value))
  ##処理終了
ocidGraphicsContext's restoreGraphicsState()
  ###変換オプション
  set ocidPropertiesDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPropertiesDict's setValue:(false) forKey:(refMe's NSImageInterlaced))
(ocidPropertiesDict's setValue:(2.2) forKey:(refMe's NSImageGamma))
  #PNG変換でデータにする
  set ocidSaveData to (ocidAardboardRep's representationUsingType:(refMe's NSPNGFileType) |properties|:(ocidPropertiesDict))
  ##########################
  ##保存
  #ファイル名
  if itemIntNo is 1 then
    set strSaveFileName to (strBaseFileName & "_1_L") as text
  else if itemIntNo is 2 then
    set strSaveFileName to (strBaseFileName & "_2_RT") as text
  else if itemIntNo is 3 then
    set strSaveFileName to (strBaseFileName & "_3_RB") as text
  end if
  #保存パス
  set ocidBaseSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false))
  set ocidSaveFilePathURL to (ocidBaseSaveFilePathURL's URLByAppendingPathExtension:("png"))
  #保存
  set listDone to (ocidSaveData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference))
  if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
  end if
end repeat

###保存先を開く
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidConfig to refMe's NSWorkspaceOpenConfiguration's configuration
(ocidConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
ocidConfig's setHides:(refMe's NSNumber's numberWithBool:false)
##
(appSharedWorkspace's openURL:(ocidSaveDirPathURL) configuration:(ocidConfig) completionHandler:(missing value))




|

画像ファイルを2in1 2upにマージする(読み方向;上から下) 修正


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
NSAlphaFirstBitmapFormatが廃止になるので
NSBitmapFormatAlphaFirstに変更した
com.cocolog-nifty.quicktimer.icefloe
NSCompositeSourceOverが廃止になるので
NSCompositingOperationSourceOverに変更
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
#############################
#ファイル選択
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set listUTI to {"public.image"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set listAliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles, showing package contents and multiple selections allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
############
#URLのARRAYに
set ocidFilePathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to (POSIX path of itemAliasFilePath) as text
  set ocidFilePath to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePathURL to (refMe's NSURL's fileURLWithPath:(ocidFilePath))
(ocidFilePathURLArray's addObject:(ocidFilePathURL))
end repeat
set numCntURL to (count of ocidFilePathURLArray) as integer
############
#並び替え
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("absoluteString") ascending:(yes) selector:("localizedStandardCompare:")
set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor)
set ocidSortedArray to ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
#ダイアログ用のURL
set ocidFirstObjectURL to ocidSortedArray's firstObject()
set ocidContainerDirPathURL to ocidFirstObjectURL's URLByDeletingLastPathComponent()
set aliasSaveDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
############
#保存先
set strMes to "保存先フォルダを選んでください" as text
set strPrompt to "保存先フォルダを選択してください" as text
try
  set aliasSaveDirPath to (choose folder strMes with prompt strPrompt default location aliasSaveDirPath with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
set strSaveDirPath to (POSIX path of aliasSaveDirPath) as text
set ocidSaveDirPath to refMe's NSString's stringWithString:(strSaveDirPath)
set ocidSaveDirPathURL to refMe's NSURL's fileURLWithPath:(ocidSaveDirPath)

############
set numOutPutPageNo to 1 as integer
repeat with itemIntNo from 0 to (numCntURL - 1) by 2
  #上ページURL取り出し
  set ocidFilePathURLR to (ocidSortedArray's objectAtIndex:(itemIntNo))
  if numCntURL > (itemIntNo + 1) then
    #下ページURL取り出し
    set ocidFilePathURLL to (ocidSortedArray's objectAtIndex:(itemIntNo + 1))
  end if
  ############DATA
  #上ページ
  set ocidOption to (refMe's NSDataReadingMappedIfSafe)
  set listDataR to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURLR) options:(ocidOption) |error|:(reference))
  if (item 2 of listDataR) ≠ (missing value) then
log (item 2 of listDataR)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
  else
    set ocidDataR to (item 1 of listDataR)
  end if
  #下ページ
  if numCntURL > (itemIntNo + 1) then
    set listDataL to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURLL) options:(ocidOption) |error|:(reference))
    if (item 2 of listDataL) ≠ (missing value) then
log (item 2 of listDataL)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
    else
      set ocidDataL to (item 1 of listDataL)
    end if
  end if
  
  ############IMAGE 上
  #イメージに変換 上ページ
  set ocidImageR to (refMe's NSImage's alloc()'s initWithData:(ocidDataR))
  #BmpRepに変換
  set ocidImageRepArrayR to ocidImageR's representations()
  set ocidImageRepR to ocidImageRepArrayR's firstObject()
  ############IMAGEのサイズ
  #ptサイズ 上
  set ocidSizeR to ocidImageRepR's |size|()
  set numWptR to ocidSizeR's width
  set numHptR to ocidSizeR's height
  #pxサイズ 上
  set numWpxR to ocidImageRepR's pixelsWide()
  set numHpxR to ocidImageRepR's pixelsHigh()
  #BmpRepを72ppiにしておく
  set ocidSetSizeR to refMe's NSMakeSize(numWpxR, numHpxR)
(ocidImageRepR's setSize:(ocidSetSizeR))
  ############IMAGE 下
  if numCntURL > (itemIntNo + 1) then
    #イメージに変換 下
    set ocidImageL to (refMe's NSImage's alloc()'s initWithData:(ocidDataL))
    #BmpRepに変換
    set ocidImageRepArrayL to ocidImageL's representations()
    set ocidImageRepL to ocidImageRepArrayL's firstObject()
    #奇数ページ対応で白紙画像を入れる
  else
    ##白紙
    set ocidImageRepL to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numWpxR) pixelsHigh:(numHpxR) bitsPerSample:8 samplesPerPixel:3 hasAlpha:false isPlanar:false colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSBitmapFormatThirtyTwoBitLittleEndian) bytesPerRow:0 bitsPerPixel:32)
    #初期化
refMe's NSGraphicsContext's saveGraphicsState()
    #読み込み
(refMe's NSGraphicsContext's setCurrentContext:(refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidImageRepL)))
    #塗り色を『白』に指定して
refMe's NSColor's whiteColor()'s |set|()
refMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:(numWpxR), height:(numHpxR)}})
    #画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()
  end if
  ##
  #ptサイズ 下
  set ocidSizeL to ocidImageRepL's |size|()
  set numWptL to ocidSizeL's width
  set numHptL to ocidSizeL's height
  #pxサイズ 下
  set numWpxL to ocidImageRepL's pixelsWide()
  set numHpxL to ocidImageRepL's pixelsHigh()
  #解像度 下
  set numResolutionL to (numWpxL / numWptL) as number
  #BmpRepを72ppiにしておく
  set ocidSetSizeL to refMe's NSMakeSize(numWpxL, numHpxL)
(ocidImageRepL's setSize:(ocidSetSizeL))
  ############出力イメージ サイズPX
  if numWpxR ≥ numWpxL then
    set numOutPutW to (numWpxR) as number
  else
    set numOutPutW to (numWpxL) as number
  end if
  set numOutPutH to (numHpxR + numHpxL) as number
  
  ############合成処理開始
  ##出力用REP
  set ocidAardboardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numOutPutW) pixelsHigh:(numOutPutH) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSBitmapFormatAlphaFirst) bytesPerRow:0 bitsPerPixel:32)
  ##ペースト位置RECT 上
  set ocidPasteRectR to {origin:{x:((numOutPutW - numWpxR) / 2), y:(numHpxL)}, |size|:{width:(numWpxR), height:(numHpxR)}}
  ##ペースト位置RECT 下
  set ocidPasteRectL to {origin:{x:((numOutPutW - numWpxL) / 2), y:(0)}, |size|:{width:(numWpxL), height:(numHpxL)}}
  
  ##元データのRECT(コピー位置) 右
  set ocidCopyRectR to {origin:{x:(0), y:(0)}, |size|:{width:(numWpxR), height:(numHpxR)}}
  ##元データのRECT(コピー位置) 左
  set ocidCopyRectL to {origin:{x:(0), y:(0)}, |size|:{width:(numWpxL), height:(numHpxL)}}
  
  ##################
  ##処理開始
  set ocidGraphicsContext to refMe's NSGraphicsContext
ocidGraphicsContext's saveGraphicsState()
  ##アートボード(出力イメージ)を処理内に読み込んで
(ocidGraphicsContext's setCurrentContext:(ocidGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)))
  ##合成 上
(ocidImageRepR's drawInRect:(ocidPasteRectR) fromRect:(ocidCopyRectR) operation:(refMe's NSCompositingOperationSourceOver) fraction:1.0 respectFlipped:false hints:(missing value))
  ##合成 下
(ocidImageRepL's drawInRect:(ocidPasteRectL) fromRect:(ocidCopyRectL) operation:(refMe's NSCompositingOperationSourceOver) fraction:1.0 respectFlipped:false hints:(missing value))
  ##処理終了
ocidGraphicsContext's restoreGraphicsState()
  
  ##################
  ###変換オプション
  set ocidPropertiesDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPropertiesDict's setValue:(false) forKey:(refMe's NSImageInterlaced))
(ocidPropertiesDict's setValue:(2.2) forKey:(refMe's NSImageGamma))
  #PNG変換でデータにする
  set ocidSaveData to (ocidAardboardRep's representationUsingType:(refMe's NSPNGFileType) |properties|:(ocidPropertiesDict))
  #保存パス
  #ページ番号0サプレス
  set strOutPutPageNo to text -3 through -1 of ("000" & (numOutPutPageNo as text)) as text
  set strSaveFileName to (strOutPutPageNo & "-" & numOutPutW & "x" & numOutPutH) as text
  set ocidBaseSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false))
  set ocidSaveFilePathURL to (ocidBaseSaveFilePathURL's URLByAppendingPathExtension:("png"))
  #保存
  set listDone to (ocidSaveData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference))
  if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
  end if
  set numOutPutPageNo to numOutPutPageNo + 1 as integer
  
end repeat


return





|

解像度変更 修正


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
# use framework "Quartz"
# use framework "CoreImage"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

on run
  
  set aliasIconPass to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns") as alias
  set strDialogText to "ドロップしても利用できます"
  set strTitleText to "画像ファイルを選んでください"
  set listButton to {"ファイルを選びます", "キャンセル"} as list
display dialog strDialogText buttons listButton default button 1 cancel button 2 with title strTitleText with icon aliasIconPass giving up after 2 with hidden answer
  
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
  set listChooseFileUTI to {"public.png", "public.jpeg"}
  set strPromptText to "イメージファイルを選んでください" as text
  set strPromptMes to "イメージファイルを選んでください" as text
  set listAliasFilePath to (choose file strPromptMes with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with showing package contents, invisibles and multiple selections allowed) as list
  
  -->値をOpenに渡たす
open listAliasFilePath
end run


on open listAliasFilePath
  ##########################
  ####解像度を指定する
  ##########################
  ###ダイアログを前面に出す
  tell current application
    set strName to name as text
  end tell
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  #
  set listResolution to {"72", "96", "120", "144", "216", "288", "300", "360"} as list
  #
  try
    set listResponse to (choose from list listResolution with title "選んでください" with prompt "解像度を選んでください" default items (item 1 of listResolution) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
  on error
log "エラーしました"
return "エラーしました"
  end try
  if (item 1 of listResponse) is false then
return "キャンセルしました"
  end if
  set strResolution to (item 1 of listResponse) as text
  set numResolution to strResolution as integer
  
  ##########################
  ####ファイルの数だけ繰り返し
  ##########################
  set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue
  set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue
  repeat with itemAliasFilePath in listAliasFilePath
    ####まずはUNIXパスにして
    set strFilePath to (POSIX path of itemAliasFilePath) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath)
    ####ファイル名を取得
    set ocidFileName to ocidFilePathURL's lastPathComponent()
    ####ファイル名から拡張子を取っていわゆるベースファイル名を取得
    set strPrefixName to ocidFileName's stringByDeletingPathExtension as text
    ####コンテナディレクトリを取得
    set ocidContainerDirURL to ocidFilePathURL's URLByDeletingLastPathComponent()
    ###拡張子を取得して小文字にしておく
    set ocidExtensionName to ocidFilePathURL's pathExtension()
    set ocidExtensionNameLowCase to ocidExtensionName's lowercaseString()
    set strExtensionName to ocidExtensionNameLowCase as text
    #####################
    #### 本処理
    #####################
    ####データ読み込み
    set ocidImage to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidFilePathURL))
    #BmpRepに変換
    set ocidImageRepArray to ocidImage's representations()
    set ocidImageRep to ocidImageRepArray's firstObject()
    set ocidSize to ocidImageRep's |size|()
    set numWptR to ocidSize's width
    set numHptR to ocidSize's height
    #プロパティを保存時用に取得
    try
      ##ちょいちょいpropertiesの取得でエラーになるので
      set ocidPropertiesDict to ocidImageRep's |properties|
    on error
      ##プロパティがある項目だけ保存用に取得する
      set ocidPropertiesDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
      set listProperties to {(refMe's NSImageColorSyncProfileData), (refMe's NSImageCompressionFactor), (refMe's NSImageCompressionMethod), (refMe's NSImageCurrentFrame), (refMe's NSImageCurrentFrameDuration), (refMe's NSImageDitherTransparency), (refMe's NSImageEXIFData), (refMe's NSImageFallbackBackgroundColor), (refMe's NSImageFrameCount), (refMe's NSImageGamma), (refMe's NSImageInterlaced), (refMe's NSImageLoopCount), (refMe's NSImageProgressive), (refMe's NSImageRGBColorTable)} as list
      repeat with itemPropertie in listProperties
        set ocidSetValue to (ocidImageRep's valueForProperty:(itemPropertie))
        if ocidSetValue ≠ (missing value) then
(ocidPropertiesDict's setObject:(ocidSetValue) forKey:(itemPropertie))
        end if
      end repeat
    end try
    #ピクセルサイズを取得
    set numPixelsWidth to ocidImageRep's pixelsWide()
    set numPixelsHeight to ocidImageRep's pixelsHigh()
    #サイズセットする比率
    set numSetResolution to (numResolution / 72.0) as number
    # ピクセルサイズに↑の比率で割って セットするポイントサイズ
    set numNewImageWidth to (numPixelsWidth / numSetResolution) as number
    set numNewImageHeight to (numPixelsHeight / numSetResolution) as number
    #####リサイズの値レコード
    set recordNewImageSize to {width:numNewImageWidth, height:numNewImageHeight} as record
    ###リサイズ
(ocidImageRep's setSize:(recordNewImageSize))
    #拡張子による分岐
    if strExtensionName is "png" then
      set ocidSaveImageType to (refMe's NSBitmapImageFileTypePNG)
      set ocidNewImageData to (ocidImageRep's representationUsingType:ocidSaveImageType |properties|:(ocidPropertiesDict))
      set ocidSaveFilePathURL to ocidFilePathURL
    else if strExtensionName is "jpg" then
      set ocidSaveImageType to (refMe's NSBitmapImageFileTypeJPEG)
      set ocidNewImageData to (ocidImageRep's representationUsingType:ocidSaveImageType |properties|:(ocidPropertiesDict))
      set ocidSaveFilePathURL to ocidFilePathURL
    else if strExtensionName is "jpeg" then
      set ocidSaveImageType to (refMe's NSBitmapImageFileTypeJPEG)
      set ocidNewImageData to (ocidImageRep's representationUsingType:ocidSaveImageType |properties|:(ocidPropertiesDict))
      set ocidSaveFilePathURL to ocidFilePathURL
    else if strExtensionName is "tif" then
      set ocidSaveImageType to (refMe's NSBitmapImageFileTypeTIFF)
      set ocidNewImageData to (ocidImageRep's representationUsingType:ocidSaveImageType |properties|:(ocidPropertiesDict))
      set ocidSaveFilePathURL to ocidFilePathURL
    else if strExtensionName is "tiff" then
      set ocidSaveImageType to (refMe's NSBitmapImageFileTypeTIFF)
      set ocidNewImageData to (ocidImageRep's representationUsingType:ocidSaveImageType |properties|:(ocidPropertiesDict))
      set ocidSaveFilePathURL to ocidFilePathURL
      (*
else if strExtensionName is "bmp" then
set ocidSaveImageType to (refMe's NSBitmapImageFileTypeBMP)
set ocidNewImageData to (ocidImageRep's representationUsingType:ocidSaveImageType |properties|:(ocidPropertiesDict))
set ocidSaveFilePathURL to ocidFilePathURL
else if strExtensionName is "gif" then
set ocidSaveImageType to (refMe's NSBitmapImageFileTypeGIF)
set ocidNewImageData to (ocidImageRep's representationUsingType:ocidSaveImageType |properties|:(ocidPropertiesDict))
set ocidSaveFilePathURL to ocidFilePathURL
*)
    else
log "上記以外の場合はPNGで別名保存"
      set ocidSaveImageType to (refMe's NSBitmapImageFileTypePNG)
      set ocidNewImageData to (ocidImageRep's representationUsingType:ocidSaveImageType |properties|:(ocidPropertiesDict))
      set strSaveFileName to (strPrefixName & ".png") as text
      set ocidSaveFilePathURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strSaveFileName))
    end if
    ###上書き保存
    set boolResults to (ocidNewImageData's writeToURL:(ocidSaveFilePathURL) atomically:true)
    #結果
    if boolResults is true then
log "処理OK"
    else
log "処理NGなのでそのままにする"
log "失敗ラベル赤を塗る"
      set boolResults to (ocidImagFilePathURL's setResourceValue:6 forKey:(refMe's NSURLLabelNumberKey) |error|:(reference))
    end if
    set ocidImageData to ""
    set ocidImageRep to ""
    set ocidNewImageData to ""
  end repeat
end open


|

画像ファイルを2in1 2upにマージする(読み方向;右から左) 修正


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
NSAlphaFirstBitmapFormatが廃止になるので
NSBitmapFormatAlphaFirstに変更した
NSCompositeSourceOverが廃止になるので
NSCompositingOperationSourceOverに変更

com.cocolog-nifty.quicktimer.icefloe
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
#############################
#ファイル選択
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set listUTI to {"public.image"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set listAliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles, showing package contents and multiple selections allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
############
#URLのARRAYに
set ocidFilePathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to (POSIX path of itemAliasFilePath) as text
  set ocidFilePath to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePathURL to (refMe's NSURL's fileURLWithPath:(ocidFilePath))
(ocidFilePathURLArray's addObject:(ocidFilePathURL))
end repeat
set numCntURL to (count of ocidFilePathURLArray) as integer
############
#並び替え
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("absoluteString") ascending:(yes) selector:("localizedStandardCompare:")
set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor)
set ocidSortedArray to ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
#ダイアログ用のURL
set ocidFirstObjectURL to ocidSortedArray's firstObject()
set ocidContainerDirPathURL to ocidFirstObjectURL's URLByDeletingLastPathComponent()
set aliasSaveDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
############
#保存先
set strMes to "保存先フォルダを選んでください" as text
set strPrompt to "保存先フォルダを選択してください" as text
try
  set aliasSaveDirPath to (choose folder strMes with prompt strPrompt default location aliasSaveDirPath with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
set strSaveDirPath to (POSIX path of aliasSaveDirPath) as text
set ocidSaveDirPath to refMe's NSString's stringWithString:(strSaveDirPath)
set ocidSaveDirPathURL to refMe's NSURL's fileURLWithPath:(ocidSaveDirPath)

############
set numOutPutPageNo to 1 as integer
repeat with itemIntNo from 0 to (numCntURL - 1) by 2
  #左右ページ取り出し
  set ocidFilePathURLR to (ocidSortedArray's objectAtIndex:(itemIntNo))
  if numCntURL > (itemIntNo + 1) then
    set ocidFilePathURLL to (ocidSortedArray's objectAtIndex:(itemIntNo + 1))
  end if
  ############DATA
  #右ページ
  set ocidOption to (refMe's NSDataReadingMappedIfSafe)
  set listDataR to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURLR) options:(ocidOption) |error|:(reference))
  if (item 2 of listDataR) ≠ (missing value) then
log (item 2 of listDataR)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
  else
    set ocidDataR to (item 1 of listDataR)
  end if
  #左ページ
  if numCntURL > (itemIntNo + 1) then
    set listDataL to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURLL) options:(ocidOption) |error|:(reference))
    if (item 2 of listDataL) ≠ (missing value) then
log (item 2 of listDataL)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
    else
      set ocidDataL to (item 1 of listDataL)
    end if
  end if
  
  ############IMAGE 右
  #イメージに変換 右
  set ocidImageR to (refMe's NSImage's alloc()'s initWithData:(ocidDataR))
  #BmpRepに変換
  set ocidImageRepArrayR to ocidImageR's representations()
  set ocidImageRepR to ocidImageRepArrayR's firstObject()
  ############IMAGEのサイズ
  #ptサイズ 右
  set ocidSizeR to ocidImageRepR's |size|()
  set numWptR to ocidSizeR's width
  set numHptR to ocidSizeR's height
  #pxサイズ 右
  set numWpxR to ocidImageRepR's pixelsWide()
  set numHpxR to ocidImageRepR's pixelsHigh()
  #BmpRepを72ppiにしておく
  set ocidSetSizeR to refMe's NSMakeSize(numWpxR, numHpxR)
(ocidImageRepR's setSize:(ocidSetSizeR))
  ############IMAGE 左
  if numCntURL > (itemIntNo + 1) then
    #イメージに変換 左
    set ocidImageL to (refMe's NSImage's alloc()'s initWithData:(ocidDataL))
    #BmpRepに変換
    set ocidImageRepArrayL to ocidImageL's representations()
    set ocidImageRepL to ocidImageRepArrayL's firstObject()
    #奇数ページ対応で白紙画像を入れる
  else
    ##白紙
    set ocidImageRepL to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numWpxR) pixelsHigh:(numHpxR) bitsPerSample:8 samplesPerPixel:3 hasAlpha:false isPlanar:false colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSBitmapFormatThirtyTwoBitLittleEndian) bytesPerRow:0 bitsPerPixel:32)
    #初期化
refMe's NSGraphicsContext's saveGraphicsState()
    #読み込み
(refMe's NSGraphicsContext's setCurrentContext:(refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidImageRepL)))
    #塗り色を『白』に指定して
refMe's NSColor's whiteColor()'s |set|()
refMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:(numWpxR), height:(numHpxR)}})
    #画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()
  end if
  ##
  #ptサイズ 左
  set ocidSizeL to ocidImageRepL's |size|()
  set numWptL to ocidSizeL's width
  set numHptL to ocidSizeL's height
  #pxサイズ 左
  set numWpxL to ocidImageRepL's pixelsWide()
  set numHpxL to ocidImageRepL's pixelsHigh()
  #解像度 左
  set numResolutionL to (numWpxL / numWptL) as number
  #BmpRepを72ppiにしておく
  set ocidSetSizeL to refMe's NSMakeSize(numWpxL, numHpxL)
(ocidImageRepL's setSize:(ocidSetSizeL))
  ############出力イメージ
  set numOutPutW to (numWpxR + numWpxL) as number
  if numHpxR ≥ numHpxL then
    set numOutPutH to numHpxR as number
  else if numHpxR < numHpxL then
    set numOutPutH to numHpxL as number
  end if
  ############合成処理開始
  ##出力用REP
  set ocidAardboardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numOutPutW) pixelsHigh:(numOutPutH) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSBitmapFormatAlphaFirst) bytesPerRow:0 bitsPerPixel:32)
  ##ペースト位置RECT 右
  set ocidPasteRectR to {origin:{x:(numWpxL), y:(numOutPutH - numHpxR)}, |size|:{width:(numWpxR), height:(numHpxR)}}
  ##ペースト位置RECT 左
  set ocidPasteRectL to {origin:{x:0, y:(numOutPutH - numHpxL)}, |size|:{width:(numWpxL), height:(numHpxL)}}
  ##元データのRECT(コピー位置) 右
  set ocidCopyRectR to {origin:{x:(0), y:(0)}, |size|:{width:(numWpxR), height:(numHpxR)}}
  ##元データのRECT(コピー位置) 左
  set ocidCopyRectL to {origin:{x:(0), y:(0)}, |size|:{width:(numWpxL), height:(numHpxL)}}
  
  ##################
  ##処理開始
  set ocidGraphicsContext to refMe's NSGraphicsContext
ocidGraphicsContext's saveGraphicsState()
  ##アートボード(出力イメージ)を処理内に読み込んで
(ocidGraphicsContext's setCurrentContext:(ocidGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)))
  ##合成 右
(ocidImageRepR's drawInRect:(ocidPasteRectR) fromRect:(ocidCopyRectR) operation:(refMe's NSCompositingOperationSourceOver) fraction:1.0 respectFlipped:false hints:(missing value))
  ##合成 左
(ocidImageRepL's drawInRect:(ocidPasteRectL) fromRect:(ocidCopyRectL) operation:(refMe's NSCompositingOperationSourceOver) fraction:1.0 respectFlipped:false hints:(missing value))
  ##処理終了
ocidGraphicsContext's restoreGraphicsState()
  
  ##################
  ###変換オプション
  set ocidPropertiesDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPropertiesDict's setValue:(false) forKey:(refMe's NSImageInterlaced))
(ocidPropertiesDict's setValue:(2.2) forKey:(refMe's NSImageGamma))
  #PNG変換でデータにする
  set ocidSaveData to (ocidAardboardRep's representationUsingType:(refMe's NSPNGFileType) |properties|:(ocidPropertiesDict))
  #保存パス
  #ページ番号0サプレス
  set strOutPutPageNo to text -3 through -1 of ("000" & (numOutPutPageNo as text)) as text
  set strSaveFileName to (strOutPutPageNo & "-" & numOutPutW & "x" & numOutPutH) as text
  set ocidBaseSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false))
  set ocidSaveFilePathURL to (ocidBaseSaveFilePathURL's URLByAppendingPathExtension:("png"))
  #保存
  set listDone to (ocidSaveData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference))
  if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
  end if
  set numOutPutPageNo to numOutPutPageNo + 1 as integer
  
end repeat


return





|

twitter投稿用画像4分割


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
1つの画像を16:9の4分割します
サイズによって切り取られる部分があります
com.cocolog-nifty.quicktimer.icefloe
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application


set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
#############################
###ダイアログを前面に出す
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
  # tell application id "com.apple.appkit.xpc.openAndSavePanelService" to activate
else
  tell current application to activate
end if
set listUTI to {"public.image"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)
#
set ocidFileName to ocidFilePathURL's lastPathComponent()
set strBaseFileName to (ocidFileName's stringByDeletingPathExtension()) as text
#
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set aliasSaveDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
############

set strMes to "保存先フォルダを選んでください" as text
set strPrompt to "保存先フォルダを選択してください" as text
try
  set aliasSaveDirPath to (choose folder strMes with prompt strPrompt default location aliasSaveDirPath with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
set strSaveDirPath to (POSIX path of aliasSaveDirPath) as text
set ocidSaveDirPath to refMe's NSString's stringWithString:(strSaveDirPath)
set ocidSaveDirPathURL to refMe's NSURL's fileURLWithPath:(ocidSaveDirPath)

############
set ocidOption to (refMe's NSDataReadingMappedIfSafe)
set listData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)
if (item 2 of listData) ≠ (missing value) then
log (item 2 of listData)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
else
  set ocidData to (item 1 of listData)
end if
############
#イメージに変換
set ocidImage to refMe's NSImage's alloc()'s initWithData:(ocidData)
#BmpRepに変換
set ocidImageRepArray to ocidImage's representations()
set ocidImageRep to ocidImageRepArray's firstObject()
#ptサイズ
set ocidSize to ocidImageRep's |size|()
set numWpt to ocidSize's width
set numHpt to ocidSize's height
#pxサイズ
set numWpx to ocidImageRep's pixelsWide()
set numHpx to ocidImageRep's pixelsHigh()
#解像度
set numResolution to (numWpx / numWpt) as number
#BmpRepを72ppiにしておく
set ocidSetSize to refMe's NSMakeSize(numWpx, numHpx)
ocidImageRep's setSize:(ocidSetSize)

############
#画像1セルサイズを計算
if numWpx ≥ numHpx then
log "横長か正方形画像"
  set numAspectH to (numHpx / 18) as number
  set numAspectW to (numAspectH * 16) as number
  if (numAspectW * 2) ≥ numWpx then
log "上下に余白でCROP"
    set numAspectW to (numWpx / 32) as number
    set numSelW to (numAspectW * 16) as number
    set numSelH to (numAspectW * 9) as number
    set numMarginTop to ((numHpx - (numAspectW * 18)) / 2) as number
    set numMarginLeft to 0 as integer
log numSelW as integer
log numSelH as integer
log numMarginTop as integer
    set ocidMakeSize to refMe's NSMakeSize(numSelW, numSelH)
  else
log "左右に余白でCROP"
    set numSelW to (numAspectH * 16) as number
    set numSelH to (numAspectH * 9) as number
    set numMarginLeft to ((numWpx - (numAspectH * 32)) / 2) as number
    set numMarginTop to 0 as integer
    set ocidMakeSize to refMe's NSMakeSize(numSelW, numSelH)
  end if
  
else if numWpx < numHpx then
log "縦長"
  set numAspectW to (numWpx / 32) as number
  set numSelW to (numAspectW * 16) as number
  set numSelH to (numAspectW * 9) as number
  set numMarginTop to ((numHpx - (numAspectW * 18)) / 2) as number
  set numMarginLeft to 0 as integer
log numSelW as integer
log numSelH as integer
log numMarginTop as integer
  set ocidMakeSize to refMe's NSMakeSize(numSelW, numSelH)
end if

set numCntRepat to 1 as integer
repeat 4 times
  ################左下
  ##出力用REP
  set ocidAardboardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numSelW) pixelsHigh:(numSelH) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSBitmapFormatAlphaFirst) bytesPerRow:0 bitsPerPixel:32)
  ##処理開始
  set ocidGraphicsContext to refMe's NSGraphicsContext
ocidGraphicsContext's saveGraphicsState()
(ocidGraphicsContext's setCurrentContext:(ocidGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)))
  ##仕上がり寸法RECT(ペースト位置)
  set ocidPasteRect to {origin:{x:0, y:0}, |size|:{width:(numSelW), height:(numSelH)}}
  ##元データのRECT(コピー位置)
  #セル毎のコピー位置
  if numCntRepat is 1 then
    set ocidCopyRect to {origin:{x:(numMarginLeft), y:(numMarginTop + numSelH)}, |size|:{width:(numSelW), height:(numSelH)}}
  else if numCntRepat is 2 then
    set ocidCopyRect to {origin:{x:(numMarginLeft + numSelW), y:(numMarginTop + numSelH)}, |size|:{width:(numSelW), height:(numSelH)}}
  else if numCntRepat is 3 then
    set ocidCopyRect to {origin:{x:(numMarginLeft), y:numMarginTop}, |size|:{width:(numSelW), height:(numSelH)}}
  else if numCntRepat is 4 then
    set ocidCopyRect to {origin:{x:(numMarginLeft + numSelW), y:numMarginTop}, |size|:{width:(numSelW), height:(numSelH)}}
  end if
  ##合成
(ocidImageRep's drawInRect:(ocidPasteRect) fromRect:(ocidCopyRect) operation:(refMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:false hints:(missing value))
  ##処理終了
ocidGraphicsContext's restoreGraphicsState()
  ###変換オプション
  set ocidPropertiesDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPropertiesDict's setValue:(false) forKey:(refMe's NSImageInterlaced))
(ocidPropertiesDict's setValue:(2.2) forKey:(refMe's NSImageGamma))
  #PNG変換でデータにする
  set ocidSaveData to (ocidAardboardRep's representationUsingType:(refMe's NSPNGFileType) |properties|:(ocidPropertiesDict))
  ##########################
  ##保存
  #ファイル名
  if numCntRepat is 1 then
    set strSaveFileName to (strBaseFileName & "_1_LT") as text
  else if numCntRepat is 2 then
    set strSaveFileName to (strBaseFileName & "_2_RT") as text
  else if numCntRepat is 3 then
    set strSaveFileName to (strBaseFileName & "_3_LB") as text
  else if numCntRepat is 4 then
    set strSaveFileName to (strBaseFileName & "_4_RB") as text
  end if
  #保存パス
  set ocidBaseSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false)
  set ocidSaveFilePathURL to ocidBaseSaveFilePathURL's URLByAppendingPathExtension:("png")
  #保存
  set listDone to (ocidSaveData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference))
  if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedFailureReason() as text
return "データ読み込みでエラーになりました"
  end if
  set numCntRepat to numCntRepat + 1 as integer
end repeat

|

[2in1]画像合成2in1 2up 右→左順


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
property strBundleID : "com.apple.Preview"


######################################
##ファイル選択
######################################
#前面に
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###ダイアログ
tell application "Finder"
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
end tell
set listUTI to {"public.png", "public.jpeg"}
set strPromptText to "ファイルを選んでください" as text
set strMesText to "ファイルを選んでください" as text
set listAliasFilePath to (choose file strMesText with prompt strPromptText default location (aliasDefaultLocation) of type listUTI with multiple selections allowed without showing package contents and invisibles) as list
#############################################
#URLリストにする
set ocidFilePathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
repeat with itemAlias in listAliasFilePath
  set strFilePath to (POSIX path of itemAlias) as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
(ocidFilePathURLArray's addObject:(ocidFilePathURL))
end repeat
#############################################
#ソートしておく
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("absoluteString") ascending:(yes) selector:("localizedStandardCompare:")
set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor)
set ocidSortedArray to ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
#
set numCntArray to (count of ocidSortedArray) as integer
#############################################
#保存先確保
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set ocidSaveDirPathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:("画像合成済みフォルダ")
#
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
set strBaseFileName to ("Composed") as text


#############################################
#本処理
set numCntComposed to 0 as integer

repeat with itemNO from 0 to (numCntArray - 1) by 2
  ##############################
  ###画像読み込みA
  set ocidAsideFileURL to (ocidSortedArray's objectAtIndex:(itemNO))
  set ocidImageDataA to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidAsideFileURL))
  #PTサイズとPXサイズを取得して解像度比を取得しておく
  set ocidImageSizePtA to ocidImageDataA's |size|()
  set ocidImageWidthPtA to ocidImageSizePtA's width()
  set ocidImageHeightPtA to ocidImageSizePtA's height()
  set ocidOsDispatchArrayA to ocidImageDataA's representations()
  set ocidBmpImageRepA to ocidOsDispatchArrayA's firstObject()
  set ocidPxWA to ocidBmpImageRepA's pixelsWide()
  set ocidPxHA to ocidBmpImageRepA's pixelsHigh()
  set numRatioA to (ocidPxWA / ocidImageWidthPtA) as number
  ##############################
  ###画像読み込みB
  set numNextNO to (itemNO + 1 as integer)
  if numNextNO > (numCntArray - 1) then
    #奇数ファイル数時の最後のページ
    set ocidBmpImageRepB to (missing value)
    set ocidPxWB to ocidPxWA
    set ocidPxHB to ocidPxHA
  else
    #PTサイズとPXサイズを取得して解像度比を取得しておく
    set ocidBsideFileURL to (ocidSortedArray's objectAtIndex:(numNextNO))
    set ocidImageDataB to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidBsideFileURL))
    set ocidImageSizePtB to ocidImageDataB's |size|()
    set ocidImageWidthPtB to ocidImageSizePtB's width()
    set ocidImageHeightPtB to ocidImageSizePtB's height()
    set ocidOsDispatchDataB to ocidImageDataB's TIFFRepresentation()
    set ocidBmpImageRepB to (refMe's NSBitmapImageRep's imageRepWithData:(ocidOsDispatchDataB))
    set ocidPxWB to ocidBmpImageRepB's pixelsWide()
    set ocidPxHB to ocidBmpImageRepB's pixelsHigh()
    set numRatioB to (ocidPxWB / ocidImageWidthPtB) as number
  end if
  ##############################
  #Aardboard生成 出力イメージ
  set ocidAardboardW to (ocidPxWA + ocidPxWB)
  if ocidPxHA > ocidPxHB then
    set ocidAardboardH to ocidPxHA
  else
    set ocidAardboardH to ocidPxHB
  end if
  set ocidAardboardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(ocidAardboardW) pixelsHigh:(ocidAardboardH) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
  ##############################
  #右側合成 R
  set ocidGraphicsContext to refMe's NSGraphicsContext
ocidGraphicsContext's saveGraphicsState()
(ocidGraphicsContext's setCurrentContext:(ocidGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)))
  ####解像度入れた画像の合成位置
  set numSetSizeWA to (ocidPxWA * numRatioA) as integer
  set numSetSizeHA to (ocidPxHA * numRatioA) as integer
  set ocidRectR to refMe's NSMakeRect(ocidPxWB, 0, numSetSizeWA, numSetSizeHA)
log ocidRectR as list
  ###Aardboard右側のRECT
  set ocidRextA to refMe's NSMakeRect(0, 0, ocidPxWA, ocidPxHA)
log ocidRextA as list
(ocidBmpImageRepA's drawInRect:(ocidRectR) fromRect:(ocidRextA) operation:(refMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:false hints:(missing value))
  ####処理終了
ocidGraphicsContext's restoreGraphicsState()
  ##############################
  if ocidBmpImageRepB is not (missing value) then
    #左側合成 L
    set ocidGraphicsContext to refMe's NSGraphicsContext
ocidGraphicsContext's saveGraphicsState()
(ocidGraphicsContext's setCurrentContext:(ocidGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)))
    ####解像度入れた画像の合成位置
    set numSetSizeWB to (ocidPxWB * numRatioB) as integer
    set numSetSizeHB to (ocidPxHB * numRatioB) as integer
    set ocidRectL to refMe's NSMakeRect(0, 0, numSetSizeWB, numSetSizeHB)
log ocidRectL as list
    ###Aardboard左側のRECT
    set ocidRextB to refMe's NSMakeRect(0, 0, ocidPxWB, ocidPxHB)
log ocidRextB as list
(ocidBmpImageRepB's drawInRect:(ocidRectL) fromRect:(ocidRextB) operation:(refMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:false hints:(missing value))
    ####処理終了
ocidGraphicsContext's restoreGraphicsState()
  end if
  
  ##############################
  #ImagePep をNSImageに
  set ocidPropertiesDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPropertiesDict's setValue:(false) forKey:(refMe's NSImageInterlaced))
(ocidPropertiesDict's setValue:(2.2) forKey:(refMe's NSImageGamma))
  set ocidSaveData to (ocidAardboardRep's representationUsingType:(refMe's NSPNGFileType) |properties|:(ocidPropertiesDict))
  
  ##############################
  #保存
  set strSaveFileName to (numCntComposed & "-" & strBaseFileName) as text
  set ocidBaseFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName))
  set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:("png"))
  #
  set listDone to (ocidSaveData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference))
  if (item 1 of listDone) is false then
return "保存に失敗しました"
  end if
  
  #合成後のファイル番号カウントアップ
  set numCntComposed to numCntComposed + 1 as integer
end repeat




|

[NSBitmapImageRep] 処理一覧

カテゴリーページ
https://quicktimer.cocolog-nifty.com/icefloe/cat76051747/index.html

基本
ピクセルサイズ取得
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-7fb9c5.html

イメージサイズの取得(表示サイズpt)
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-278688.html

画像解像度取得
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-ea8e98.html

画像の解像度を72ppiに変更する
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-fc01b2.html

画像の解像度を144ppiに変更する
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-70cf76.html

画像のカラースペースを取得
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-d711d0.html



画像生成
画像を生成する
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-048089.html

生成した画像に色を塗る
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-c4abd5.html

生成した画像に文字を描画する
https://quicktimer.cocolog-nifty.com/icefloe/2024/02/post-fe5b34.html

[NSBitmapImageRep]CMYKカラーのTIFFを作る
https://quicktimer.cocolog-nifty.com/icefloe/2022/09/post-494202.html

[NSBitmapImageRep]8bitグレーTIFFを作る
https://quicktimer.cocolog-nifty.com/icefloe/2022/09/post-55237c.html



リサイズ
[NSBitmapImageRep]イメージサイズ変更
https://quicktimer.cocolog-nifty.com/icefloe/2023/06/post-46c144.html
複数画像のリサイズ(高さ揃え)saveGraphicsState使用
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-497d06.html
複数画像のリサイズ(高さ揃え)lockFocus使用(非推奨)
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-75d498.html


書出
マルチページTIFFをページ毎で別ファイルに書き出す
https://quicktimer.cocolog-nifty.com/icefloe/2023/06/post-759904.html

[Gif]gifアニメーションの各コマを別ファイルに保存(イメージシーケンス保存)
https://quicktimer.cocolog-nifty.com/icefloe/2023/05/post-4c0c6b.html

|

生成した画像に文字を描画する


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "CoreImage"
use scripting additions

property refMe : a reference to current application

##偶数値限定
set numPixelsWidth to 720 as integer
set numPixelsHeight to 360 as integer
set numResolution to 144 as integer
#
set numHarfPixelsWidth to (numPixelsWidth / 2) as integer
set numHarfPixelsHeight to (numPixelsHeight / 2) as integer
#ファイル名
set strFileName to (numHarfPixelsWidth & "x" & numHarfPixelsHeight & "@2x.png") as text
#パス
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strFileName)

#画像を生成
set ocidBitmapFormat to refMe's NSBitmapFormatAlphaFirst
set ocidColorSpaceName to refMe's NSCalibratedRGBColorSpace
set ocidArtBoardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(720) pixelsHigh:(360) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
########画像編集開始
refMe's NSGraphicsContext's saveGraphicsState()
set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep))
(refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
#色指定
set ocidSetColor to refMe's NSColor's colorWithSRGBRed:(0.1) green:(0.75) blue:(0.26) alpha:(1.0)
ocidSetColor's |set|()
###画像生成 原点は画像左下
refMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:(numPixelsWidth), height:(numPixelsHeight)}})
####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()
########画像編集終わり
########文字入力開始
###フォント初期化
# set appFontManager to refMe's NSFontManager
# set appSharedFontManager to appFontManager's sharedFontManager()
###設定用のレコード
set ocidTextAttr to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
###共通項目
set ocidStyle to refMe's NSParagraphStyle's defaultParagraphStyle
(ocidTextAttr's setObject:(ocidStyle) forKey:(refMe's NSParagraphStyleAttributeName))
#色指定
set ocidTextColor to (refMe's NSColor's colorWithSRGBRed:(0) green:(0) blue:(0) alpha:(1.0))
(ocidTextAttr's setObject:(ocidTextColor) forKey:(refMe's NSForegroundColorAttributeName))
########画像編集開始(テキスト描画)
refMe's NSGraphicsContext's saveGraphicsState()
#画像指定
set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep))
#コンテキスト化
(refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
#印字内容
set ocidText to (refMe's NSString's stringWithString:("Hello AppleScript"))
#フォントとサイズ指定
set ocidFont to (refMe's NSFont's fontWithName:("Helvetica-Bold") |size|:(52))
#フォント情報を付与
(ocidTextAttr's setObject:(ocidFont) forKey:(refMe's NSFontAttributeName))
#カーニング
(ocidTextAttr's setObject:(-1.8) forKey:(refMe's NSKernAttributeName))
#描画位置 左下基準
set ocidTextOrigin to refMe's NSMakePoint((160), (150))
#描画内容の確定↓ NSGraphicsContext'sに渡す
(ocidText's drawAtPoint:(ocidTextOrigin) withAttributes:(ocidTextAttr))
########画像編集終了(テキスト描画)
refMe's NSGraphicsContext's restoreGraphicsState()

#保存用オプション
set ocidPropertyDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPropertyDict's setObject:(refMe's NSNumber's numberWithBool:(false)) forKey:(refMe's NSImageInterlaced))
(ocidPropertyDict's setObject:(refMe's NSNumber's numberWithFloat:(1 / 2.2)) forKey:(refMe's NSImageGamma))
set ocidImageType to (refMe's NSBitmapImageFileTypePNG)
#イメージサイズを指定(ここで解像度が144ppiになる)
set ocidPixelsSize to refMe's NSMakeSize(numHarfPixelsWidth, numHarfPixelsHeight)
(ocidArtBoardRep's setSize:(ocidPixelsSize))
#インラインデータに変換して
set ocidImageData to (ocidArtBoardRep's representationUsingType:(ocidImageType) |properties|:(ocidPropertyDict))
#保存
set listDone to (ocidImageData's writeToURL:ocidSaveFilePathURL options:0 |error|:(reference))





|

生成した画像に色を塗る


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "CoreImage"
use scripting additions

property refMe : a reference to current application

##偶数値限定
set numPixelsWidth to 720 as integer
set numPixelsHeight to 360 as integer
set numResolution to 144 as integer
#
set numHarfPixelsWidth to (numPixelsWidth / 2) as integer
set numHarfPixelsHeight to (numPixelsHeight / 2) as integer
#ファイル名
set strFileName to (numHarfPixelsWidth & "x" & numHarfPixelsHeight & "@2x.png") as text
#パス
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strFileName)

#画像を生成
set ocidBitmapFormat to refMe's NSBitmapFormatAlphaFirst
set ocidColorSpaceName to refMe's NSCalibratedRGBColorSpace
set ocidArtBoardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(720) pixelsHigh:(360) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
########画像編集開始
refMe's NSGraphicsContext's saveGraphicsState()
set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep))
(refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
#色指定
set ocidSetColor to refMe's NSColor's colorWithSRGBRed:(0.1) green:(0.75) blue:(0.26) alpha:(1.0)
ocidSetColor's |set|()
###画像生成 原点は画像左下
refMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:(numPixelsWidth), height:(numPixelsHeight)}})
####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()
########画像編集終わり
#保存用オプション
set ocidPropertyDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPropertyDict's setObject:(refMe's NSNumber's numberWithBool:(false)) forKey:(refMe's NSImageInterlaced))
(ocidPropertyDict's setObject:(refMe's NSNumber's numberWithFloat:(1 / 2.2)) forKey:(refMe's NSImageGamma))
set ocidImageType to (refMe's NSBitmapImageFileTypePNG)
#イメージサイズを指定(ここで解像度が144ppiになる)
set ocidPixelsSize to refMe's NSMakeSize(numHarfPixelsWidth, numHarfPixelsHeight)
(ocidArtBoardRep's setSize:(ocidPixelsSize))
#インラインデータに変換して
set ocidImageData to (ocidArtBoardRep's representationUsingType:(ocidImageType) |properties|:(ocidPropertyDict))
#保存
set listDone to (ocidImageData's writeToURL:ocidSaveFilePathURL options:0 |error|:(reference))





|

画像を生成する


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

##偶数値限定
set numPixelsWidth to 720 as integer
set numPixelsHeight to 360 as integer
set numResolution to 144 as integer
#
set numHarfPixelsWidth to (numPixelsWidth / 2) as integer
set numHarfPixelsHeight to (numPixelsHeight / 2) as integer
#ファイル名
set strFileName to (numHarfPixelsWidth & "x" & numHarfPixelsHeight & "@2x.png") as text
#パス
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strFileName)
#画像を生成
set ocidBitmapFormat to refMe's NSBitmapFormatAlphaFirst
set ocidColorSpaceName to refMe's NSCalibratedRGBColorSpace
set ocidArtBoardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(720) pixelsHigh:(360) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
#保存用オプション
set ocidPropertyDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPropertyDict's setObject:(refMe's NSNumber's numberWithBool:(false)) forKey:(refMe's NSImageInterlaced))
(ocidPropertyDict's setObject:(refMe's NSNumber's numberWithFloat:(1 / 2.2)) forKey:(refMe's NSImageGamma))
set ocidImageType to (refMe's NSBitmapImageFileTypePNG)
#イメージサイズを指定(ここで解像度が144ppiになる)
set ocidPixelsSize to refMe's NSMakeSize(numHarfPixelsWidth, numHarfPixelsHeight)
(ocidArtBoardRep's setSize:(ocidPixelsSize))
#インラインデータに変換して
set ocidImageData to (ocidArtBoardRep's representationUsingType:(ocidImageType) |properties|:(ocidPropertyDict))
#保存
set listDone to (ocidImageData's writeToURL:ocidSaveFilePathURL options:0 |error|:(reference))





|

より以前の記事一覧

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom