CIImage

[CoreImage]チェキサイズのフレームを画像に合成する


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "UniformTypeIdentifiers"
009use framework "AppKit"
010use framework "CoreImage"
011use framework "CoreGraphics"
012use framework "QuartzCore"
013
014use scripting additions
015property refMe : a reference to current application
016
017set appFileManager to refMe's NSFileManager's defaultManager()
018set strName to (name of current application) as text
019if strName is "osascript" then
020  tell application "Finder" to activate
021else
022  tell current application to activate
023end if
024set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
025set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
026set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
027#
028set listUTI to {"public.image"} as list
029set strMes to ("ファイルを選んでください") as text
030set strPrompt to ("ファイルを選んでください") as text
031try
032  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
033on error
034  log "エラーしました"
035  return "エラーしました"
036end try
037
038repeat with itemAliasFilePath in listAliasFilePath
039  #入力
040  set strFilePath to (POSIX path of itemAliasFilePath) as text
041  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
042  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
043  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
044  #拡張子とったベースファイルパス
045  set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
046  #保存パス
047  set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:("Frame.png"))
048  
049  ##NSDATAに読み込む
050  set ocidOption to (refMe's NSDataReadingMappedIfSafe)
051  set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference))
052  if (item 2 of listResponse) = (missing value) then
053    log "正常処理"
054    set ocidReadData to (item 1 of listResponse)
055  else if (item 2 of listResponse) ≠ (missing value) then
056    set strErrorNO to (item 2 of listResponse)'s code() as text
057    set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
058    refMe's NSLog("■:" & strErrorNO & strErrorMes)
059    return "エラーしました" & strErrorNO & strErrorMes
060  end if
061  
062  #NSDATAをCIimageに読み込み
063  set ocidCIimage to (refMe's CIImage's alloc()'s initWithData:(ocidReadData))
064  #Rectを取り出して
065  set listReadRect to ocidCIimage's extent()
066  #ピクセルサイズ
067  set numReadW to (item 1 of (item 2 of listReadRect)) as integer
068  set numReadH to (item 2 of (item 2 of listReadRect)) as integer
069  #縦横比を計算 Wで1.6 miniで 0.74
070  set numWHscale to numReadW / numReadH as number
071  log numWHscale
072  #
073  if numReadW > numReadH then
074    #横型
075    #Wide
076    set numW to 612 as integer
077    set numH to 488 as integer
078    set ocidMaskRect to refMe's NSRect's NSMakeRect(28, 108, 556, 352)
079    set numCropInX to (item 1 of (item 1 of ocidMaskRect)) as integer
080    set numCropInY to (item 2 of (item 1 of ocidMaskRect)) as integer
081    set numCropInW to (item 1 of (item 2 of ocidMaskRect)) as integer
082    set numCropInH to (item 2 of (item 2 of ocidMaskRect)) as integer
083    #リサイズ用のスケール
084    if numWHscale > 1.59 then
085      set numScale to (numCropInH / numReadH) as number
086    else
087      set numScale to (numCropInW / numReadW) as number
088    end if
089  else if numReadW < numReadH then
090    #縦型
091    #mini
092    set numW to 306 as integer
093    set numH to 488 as integer
094    set ocidMaskRect to refMe's NSRect's NSMakeRect(23, 108, 260, 352)
095    set numCropInX to (item 1 of (item 1 of ocidMaskRect)) as integer
096    set numCropInY to (item 2 of (item 1 of ocidMaskRect)) as integer
097    set numCropInW to (item 1 of (item 2 of ocidMaskRect)) as integer
098    set numCropInH to (item 2 of (item 2 of ocidMaskRect)) as integer
099    if numWHscale > 0.74 then
100      set numScale to (numCropInH / numReadH) as number
101    else
102      set numScale to (numCropInW / numReadW) as number
103    end if
104    
105  else if numWHscale = 1 then
106    #正方形
107    #SQ
108    set numW to 408 as integer
109    set numH to 488 as integer
110    set ocidMaskRect to refMe's NSRect's NSMakeRect(28, 108, 352, 352)
111    set numCropInW to (item 1 of (item 2 of ocidMaskRect)) as integer
112    set numCropInH to (item 2 of (item 2 of ocidMaskRect)) as integer
113    #リサイズ用のスケール短編合わせ
114    set numScale to (numCropInW / numReadW) as number
115  end if
116  ##########################
117  #ペーストするフレーム画像作成
118  #カラーICC
119  set strIccFilePath to ("/System/Library/ColorSync/Profiles/sRGB Profile.icc") as text
120  set ocidIccFilePathStr to (refMe's NSString's stringWithString:(strIccFilePath))
121  set ocidIccFilePath to ocidIccFilePathStr's stringByStandardizingPath
122  set ocidIccFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidIccFilePath) isDirectory:(false))
123  set ocidProfileData to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidIccFilePathURL))
124  #セットするRECT
125  set ocidDrawRect to refMe's NSRect's NSMakeRect(0, 0, numW, numH)
126  # RGB系のカラースペース
127  set ocidColorSpaceName to (refMe's NSCalibratedRGBColorSpace)
128  # アルファあり
129  set ocidBitmapFormat to (refMe's NSAlphaFirstBitmapFormat)
130  #アートボード
131  set ocidFrameRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numW) pixelsHigh:(numH) bitsPerSample:(8) samplesPerPixel:(4) hasAlpha:(true) isPlanar:(false) colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:(0) bitsPerPixel:(32))
132  #カラーを定義
133  #白背景
134  set ocidBackgroundColor to (refMe's NSColor's colorWithSRGBRed:(1) green:(1) blue:(1) alpha:(1))
135  #抜きのアルファ
136  set ocidAlphaColor to (refMe's NSColor's colorWithSRGBRed:(1) green:(1) blue:(1) alpha:(0))
137  #
138  #【NSGraphicsContext's】▼
139  refMe's NSGraphicsContext's saveGraphicsState()
140  #Context 選択した画像を読み込んで
141  set ocidSetImageContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidFrameRep))
142  (ocidSetImageContext's setShouldAntialias:(true))
143  (ocidSetImageContext's setImageInterpolation:(refMe's NSImageInterpolationHigh))
144  (ocidSetImageContext's setColorRenderingIntent:(refMe's NSColorRenderingIntentRelativeColorimetric))
145  #生成された画像でNSGraphicsContext初期化
146  (refMe's NSGraphicsContext's setCurrentContext:(ocidSetImageContext))
147  
148  #【1】RGB値で背景色=白をセットして
149  ocidBackgroundColor's |set|()
150  #指定した色で背景を塗る
151  refMe's NSRectFill(ocidDrawRect)
152  
153  #マスクパス角丸20PX
154  set ocidMaskPath to (refMe's NSBezierPath's bezierPathWithRoundedRect:(ocidMaskRect) xRadius:(4) yRadius:(4))
155  #【2】マスクをセット
156  ocidMaskPath's addClip()
157  
158  #【3】アルファ=透過をマスク内に指定する
159  ocidAlphaColor's |set|()
160  #透過色をマスク範囲内に指定
161  refMe's NSRectFill(ocidMaskRect)
162  
163  #処理終了
164  refMe's NSGraphicsContext's restoreGraphicsState()
165  #【NSGraphicsContext's】▲
166  #出来上がったフレームイメージをCIimageにしておく
167  set ocidFrameCiImage to (refMe's CIImage's alloc()'s initWithBitmapImageRep:(ocidFrameRep))
168  
169  ##########################
170  #リサイズ定義
171  set appTransform to refMe's CGAffineTransformMakeScale(numScale, numScale)
172  #リサイズ
173  set ocidResizeImage to (ocidCIimage's imageByApplyingTransform:(appTransform))
174  #リサイズ後のピクセルサイズ
175  set listResizedRect to ocidResizeImage's extent()
176  set numResizedW to (item 1 of (item 2 of listResizedRect)) as integer
177  set numResizedH to (item 2 of (item 2 of listResizedRect)) as integer
178  log numResizedW
179  log numResizedH
180  #CROPのRECTを計算
181  if numReadW > numReadH then
182    set numSetX to ((numResizedW - numCropInW) / 2) as integer
183    set numSetY to ((numResizedH - numCropInH) / 2) as integer
184    set ocidImageRect to refMe's NSRect's NSMakeRect(numSetX, numSetY, numCropInW, numCropInH)
185    set ocidImageSize to refMe's NSSize's NSMakeSize(numW, numH)
186  else if numReadW < numReadH then
187    set numSetX to ((numResizedW - numCropInW) / 2) as integer
188    set numSetY to ((numResizedH - numCropInH) / 2) as integer
189    set ocidImageRect to refMe's NSRect's NSMakeRect(numSetX, numSetY, numCropInW, numCropInH)
190    set ocidImageSize to refMe's NSSize's NSMakeSize(numW, numH)
191  else if numReadW = numReadH then
192    set ocidImageRect to refMe's NSRect's NSMakeRect(0, 0, 408, 488)
193    set ocidImageSize to refMe's NSSize's NSMakeSize(numW, numH)
194  end if
195  ################
196  #元画像をフレームサイズでCROP
197  set ocidCgRect to refMe's NSRectToCGRect(ocidImageRect)
198  set ocidCropRect to (refMe's CIVector's vectorWithCGRect:(ocidCgRect))
199  #フィルター定義
200  set appCropFilter to (refMe's CIFilter's filterWithName:("CICrop"))
201  (appCropFilter's setValue:(ocidResizeImage) forKey:(refMe's kCIInputImageKey))
202  (appCropFilter's setValue:(ocidCropRect) forKey:("inputRectangle"))
203  #フィルタ実行
204  set ocidCropImage to appCropFilter's outputImage()
205  
206  ################
207  #
208  set numSetTransX to numSetX - numCropInX
209  set numSetTransY to (numSetY - numCropInY)
210  #負の数になったら整数にする
211  if numSetTransY < 0 then
212    set numSetTransY to (((numSetTransY) ^ 2) ^ 0.5) as number
213  end if
214  set appTranslation to refMe's CGAffineTransformMakeTranslation(-numSetTransX, numSetTransY)
215  set appTopImage to (ocidCropImage's imageByApplyingTransform:(appTranslation))
216  #
217  set appFilter to (refMe's CIFilter's filterWithName:("CISourceOverCompositing"))
218  (appFilter's setValue:(ocidFrameCiImage) forKey:(refMe's kCIInputImageKey))
219  (appFilter's setValue:(appTopImage) forKey:(refMe's kCIInputBackgroundImageKey))
220  set ocidCreationCiImage to appFilter's outputImage()
221  #ImageRepに変換
222  set ocidSaveImageRep to (refMe's NSBitmapImageRep's alloc()'s initWithCIImage:(ocidCreationCiImage))
223  
224  ################
225  #保存オプション
226  set ocidProperty to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
227  (ocidProperty's setObject:(refMe's NSNumber's numberWithBool:false) forKey:(refMe's NSImageInterlaced))
228  (ocidProperty's setObject:(refMe's NSNumber's numberWithDouble:(1 / 2.2)) forKey:(refMe's NSImageGamma))
229  #保存
230  set ocidNSInlineData to (ocidSaveImageRep's representationUsingType:(refMe's NSBitmapImageFileTypePNG) |properties|:(ocidProperty))
231  set boolDone to (ocidNSInlineData's writeToURL:(ocidSaveFilePathURL) atomically:true)
232  
233  
234  
235end repeat
236
237
238return
AppleScriptで生成しました

|

[CoreImage]画像のリサイズ(imageByApplyingTransform) ダイアログを付けて 保存ファイル名にピクセルサイズ入り


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "UniformTypeIdentifiers"
009use framework "AppKit"
010use framework "CoreImage"
011use framework "CoreGraphics"
012use framework "QuartzCore"
013use scripting additions
014property refMe : a reference to current application
015
016
017########設定項目
018#長編のサイズ(出力イメージのリサイズ後のピクセルサイズ)
019set numPxSizeMax to 720 as integer
020
021set appFileManager to refMe's NSFileManager's defaultManager()
022set strName to (name of current application) as text
023if strName is "osascript" then
024  tell application "Finder" to activate
025else
026  tell current application to activate
027end if
028set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
029set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
030set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
031#
032set listUTI to {"public.image"} as list
033set strMes to ("ファイルを選んでください") as text
034set strPrompt to ("ファイルを選んでください") as text
035try
036  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
037on error
038  log "エラーしました"
039  return "エラーしました"
040end try
041#ファイルを順に処理
042repeat with itemAliasFilePath in listAliasFilePath
043  #入力
044  set strFilePath to (POSIX path of itemAliasFilePath) as text
045  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
046  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
047  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
048  #拡張子とったベースファイルパス
049  set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
050  ###########本処理
051  ##NSDATAに読み込む
052  set ocidOption to (refMe's NSDataReadingMappedIfSafe)
053  set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference))
054  if (item 2 of listResponse) = (missing value) then
055    log "正常処理"
056    set ocidReadData to (item 1 of listResponse)
057  else if (item 2 of listResponse) ≠ (missing value) then
058    set strErrorNO to (item 2 of listResponse)'s code() as text
059    set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
060    refMe's NSLog("■:" & strErrorNO & strErrorMes)
061    return "エラーしました" & strErrorNO & strErrorMes
062  end if
063  #NSDATAをCIimageに読み込み
064  set ocidCIimage to (refMe's CIImage's alloc()'s initWithData:(ocidReadData))
065  #ピクセルサイズ
066  set listReadRect to ocidCIimage's extent()
067  set numReadW to (item 1 of (item 2 of listReadRect)) as integer
068  set numReadH to (item 2 of (item 2 of listReadRect)) as integer
069  #長編サイズでリサイズ
070  if numReadW > numReadH then
071    set numScale to (numPxSizeMax / numReadW) as number
072  else if numReadW < numReadH then
073    set numScale to (numPxSizeMax / numReadH) as number
074  else if numReadW = numReadH then
075    set numScale to (numPxSizeMax / numReadH) as number
076  end if
077  ################
078  #スケーリングフィルタ生成
079  set appTransform to refMe's CGAffineTransformMakeScale(numScale, numScale)
080  #リサイズ実行
081  set ocidResizeImage to (ocidCIimage's imageByApplyingTransform:(appTransform))
082  #リサイズ後のピクセルサイズ
083  set listReadRect to ocidResizeImage's extent()
084  set numReadW to (item 1 of (item 2 of listReadRect)) as integer
085  set numReadH to (item 2 of (item 2 of listReadRect)) as integer
086  #ImageRepに変換
087  set ocidSaveImageRep to (refMe's NSBitmapImageRep's alloc()'s initWithCIImage:(ocidResizeImage))
088  #保存拡張子
089  set strSaveExtension to (numReadW & "x" & numReadH & ".png" ) as text
090  #保存パス
091  set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:(strSaveExtension))
092  ####保存オプション
093  set ocidProperty to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
094  (ocidProperty's setObject:(refMe's NSNumber's numberWithBool:false) forKey:(refMe's NSImageInterlaced))
095  (ocidProperty's setObject:(refMe's NSNumber's numberWithDouble:(1 / 2.2)) forKey:(refMe's NSImageGamma))
096  ##保存
097  set ocidNSInlineData to (ocidSaveImageRep's representationUsingType:(refMe's NSBitmapImageFileTypePNG) |properties|:(ocidProperty))
098  set boolDone to (ocidNSInlineData's writeToURL:(ocidSaveFilePathURL) atomically:true)
099  
100  
101end repeat
102
103
104
AppleScriptで生成しました

|

[CoreImage]画像のリサイズ(imageByApplyingTransform)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "UniformTypeIdentifiers"
009use framework "AppKit"
010use framework "CoreImage"
011use framework "CoreGraphics"
012use framework "QuartzCore"
013
014use scripting additions
015property refMe : a reference to current application
016
017#長編のサイズ(出力イメージのリサイズ後のピクセルサイズ)
018set numPxSizeMax to 720 as integer
019
020set strFilePath to "/System/Library/Desktop Pictures/.wallpapers/Sequoia Sunrise/Sequoia Sunrise.heic" as text
021set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
022set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
023set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
024
025##NSDATAに読み込む
026set ocidOption to (refMe's NSDataReadingMappedIfSafe)
027set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
028if (item 2 of listResponse) = (missing value) then
029  log "正常処理"
030  set ocidReadData to (item 1 of listResponse)
031else if (item 2 of listResponse) ≠ (missing value) then
032  set strErrorNO to (item 2 of listResponse)'s code() as text
033  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
034  refMe's NSLog("■:" & strErrorNO & strErrorMes)
035  return "エラーしました" & strErrorNO & strErrorMes
036end if
037
038#NSDATAをCIimageに読み込み
039set ocidCIimage to refMe's CIImage's alloc()'s initWithData:(ocidReadData)
040#ピクセルサイズ
041set listReadRect to ocidCIimage's extent()
042set numReadW to (item 1 of (item 2 of listReadRect)) as integer
043set numReadH to (item 2 of (item 2 of listReadRect)) as integer
044#長編サイズでリサイズ
045if numReadW > numReadH then
046  set numScale to (numPxSizeMax / numReadW) as number
047else if numReadW < numReadH then
048  set numScale to (numPxSizeMax / numReadH) as number
049else if numReadW = numReadH then
050  set numScale to (numPxSizeMax / numReadH) as number
051  
052end if
053################
054#スケーリングフィルタ生成
055set appTransform to refMe's CGAffineTransformMakeScale(numScale, numScale)
056#リサイズ実行
057set ocidResizeImage to ocidCIimage's imageByApplyingTransform:(appTransform)
058
059#ImageRepに変換
060set ocidSaveImageRep to refMe's NSBitmapImageRep's alloc()'s initWithCIImage:(ocidResizeImage)
061
062#保存
063set strSaveFilePath to "~/Desktop/ResizeImage-save.png" as text
064set ocidSaveFilePathStr to refMe's NSString's stringWithString:(strSaveFilePath)
065set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath()
066set ocidSaveFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveFilePath) isDirectory:false)
067####保存オプション
068set ocidProperty to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
069(ocidProperty's setObject:(refMe's NSNumber's numberWithBool:false) forKey:(refMe's NSImageInterlaced))
070(ocidProperty's setObject:(refMe's NSNumber's numberWithDouble:(1 / 2.2)) forKey:(refMe's NSImageGamma))
071##保存
072set ocidNSInlineData to (ocidSaveImageRep's representationUsingType:(refMe's NSBitmapImageFileTypePNG) |properties|:(ocidProperty))
073set boolDone to (ocidNSInlineData's writeToURL:(ocidSaveFilePathURL) atomically:true)
AppleScriptで生成しました

|

HEICのOrientation (画像の表示の回転)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#HEICはPDFと同様に 表示の回転 をセットできる
004(* HEICのOrientationの値
0051: "天地向反転無 0"
0062: "天地向左右反転 0"
0073: "天地逆180度回転 180"
0084: "天地逆180度回転 左右反転 180"
0095: "左90度回転左右反転 270"
0106: "右90度回転 90"
0117: "右90度回転左右反転 90"
0128: "左90度回転 270"
013https://developer.apple.com/documentation/imageio/cgimagepropertyorientation
014*)
015#com.cocolog-nifty.quicktimer.icefloe
016----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
017use AppleScript version "2.8"
018use framework "Foundation"
019use framework "CoreImage"
020use framework "AppKit"
021use scripting additions
022
023property refMe : a reference to current application
024
025set recordOrientation to {|1|:"天地向反転無 0", |2|:"天地向左右反転 0", |3|:"天地逆180度回転 180", |4|:"天地逆180度回転 左右反転 180", |5|:"左90度回転左右反転 270", |6|:"右90度回転 90", |7|:"右90度回転左右反転 90", |8|:"左90度回転 270"} as record
026set ocidOrientationDict to refMe's NSDictionary's dictionaryWithDictionary:(recordOrientation)
027
028log (refMe's kCGImagePropertyOrientationUp) as integer
029-->1
030log (refMe's kCGImagePropertyOrientationUpMirrored) as integer
031-->2
032log (refMe's kCGImagePropertyOrientationDown) as integer
033-->3
034log (refMe's kCGImagePropertyOrientationDownMirrored) as integer
035-->4
036log (refMe's kCGImagePropertyOrientationLeftMirrored) as integer
037-->5
038log (refMe's kCGImagePropertyOrientationRight) as integer
039-->6
040log (refMe's kCGImagePropertyOrientationRightMirrored) as integer
041-->7
042log (refMe's kCGImagePropertyOrientationLeft) as integer
043-->8
044
045
046##パス
047set strFilePath to ("/System/Library/Desktop Pictures/Hello Metallic Blue.heic") as text
048set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
049set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
050set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false)
051
052###################################
053#読み込みNSDATA
054set ocidOption to (refMe's NSDataReadingMappedIfSafe)
055set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
056if (item 2 of listResponse) = (missing value) then
057  log "正常処理"
058  set ocidReadData to (item 1 of listResponse)
059else if (item 2 of listResponse) ≠ (missing value) then
060  log (item 2 of listResponse)'s code() as text
061  log (item 2 of listResponse)'s localizedDescription() as text
062  return "エラーしました"
063end if
064
065###################################
066#propertiesから取得する方法
067#CIImageに読み込んで
068set ocidCIImageData to (refMe's CIImage's imageWithData:(ocidReadData) options:(missing value))
069#メタデータ
070set ocidOripertesDict to ocidCIImageData's |properties|()
071#回転
072set ocidOrientation to ocidOripertesDict's valueForKey:("Orientation")
073set strOrientation to ocidOrientation as text
074if strOrientation is not "1" then
075  log "画像に表示の回転がセットされています"
076  log (ocidOrientationDict's valueForKey:(strOrientation)) as text
077else
078  log "画像は現在天地向きです"
079  log (ocidOrientationDict's valueForKey:(strOrientation)) as text
080end if
081
082
AppleScriptで生成しました

|

[CIImage]画像のメタデータを取得 表示する(テキスト表示簡易版)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#com.cocolog-nifty.quicktimer.icefloe
004#
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "CoreImage"
009use framework "AppKit"
010use scripting additions
011
012property refMe : a reference to current application
013
014
015
016on run
017  
018  set aliasIconPass to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns") as alias
019  set strDialogText to "ドロップしても利用できます"
020  set strTitleText to "画像ファイルを選んでください"
021  set listButton to {"ファイルを選びます", "キャンセル"} as list
022  display dialog strDialogText buttons listButton default button 1 cancel button 2 with title strTitleText with icon aliasIconPass giving up after 1 with hidden answer
023  
024  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
025  set listChooseFileUTI to {"public.image"}
026  set strPromptText to "イメージファイルを選んでください" as text
027  set strPromptMes to "イメージファイルを選んでください" as text
028  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
029  -->値をOpenに渡たす
030  open listAliasFilePath
031end run
032
033
034on open listAliasFilePath
035  ###出力用のテキスト
036  set ocidOutPutString to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
037  #画像の数だけ繰り返し
038  repeat with itemAliasFilePath in listAliasFilePath
039    ###入力ファイルパス
040    set aliasFilePath to itemAliasFilePath as alias
041    set strFilePath to (POSIX path of aliasFilePath) as text
042    (ocidOutPutString's appendString:(strFilePath))
043    (ocidOutPutString's appendString:("\n"))
044    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
045    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
046    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
047    ###イメージ読み込み
048    set ocidImageData to (refMe's CIImage's imageWithContentsOfURL:(ocidFilePathURL))
049    set ocidPropertiesDict to ocidImageData's |properties|()
050    set ocidAllKeys to ocidPropertiesDict's allKeys()
051    ###プロパティの数だけ繰り返す
052    repeat with itemKey in ocidAllKeys
053      if (itemKey as text) contains "{" then
054        set ocidValueDict to (ocidPropertiesDict's objectForKey:(itemKey))
055        set ocidValueAllKeys to ocidValueDict's allKeys()
056        repeat with itemValueKey in ocidValueAllKeys
057          set ocidChilValue to (ocidValueDict's objectForKey:(itemValueKey))
058          if (ocidChilValue's className() as text) contains "Array" then
059            log "Arrayの場合は何もしない"
060          else if (ocidChilValue's className() as text) contains "Data" then
061            log "Dataの場合は何もしない"
062          else if (ocidChilValue's className() as text) contains "Dict" then
063            log "Dictの場合は何もしない"
064          else
065            set strSetValue to (itemValueKey as text) & " : " & (ocidChilValue as text)
066            (ocidOutPutString's appendString:(strSetValue))
067            (ocidOutPutString's appendString:("\n"))
068          end if
069        end repeat
070      else
071        set ocidValue to (ocidPropertiesDict's valueForKey:(itemKey))
072        set strSetValue to (itemKey as text) & " : " & (ocidValue as text)
073        (ocidOutPutString's appendString:(strSetValue))
074        (ocidOutPutString's appendString:("\n"))
075      end if
076    end repeat
077    (ocidOutPutString's appendString:("\n"))
078    (ocidOutPutString's appendString:("\n"))
079  end repeat
080  
081  ###テキスト保存先(再起動時に自動で削除されます)
082  set appFileManager to refMe's NSFileManager's defaultManager()
083  set ocidTempDirURL to appFileManager's temporaryDirectory()
084  set ocidUUID to refMe's NSUUID's alloc()'s init()
085  set ocidUUIDString to ocidUUID's UUIDString
086  set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
087  #
088  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
089  # 777-->511 755-->493 700-->448 766-->502
090  ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
091  set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
092  if (item 1 of listDone) is true then
093    log "createDirectoryAtURL 正常処理"
094  else if (item 2 of listDone) ≠ (missing value) then
095    log (item 2 of listDone)'s code() as text
096    log (item 2 of listDone)'s localizedDescription() as text
097    return "createDirectoryAtURL エラーしました"
098  end if
099  
100  ###パス
101  set strFileName to "CIimageProperties.txt" as text
102  set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
103  ###保存
104  set listDone to ocidOutPutString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
105  if (item 1 of listDone) is true then
106    log "writeToURL 正常処理"
107  else if (item 2 of listDone) ≠ (missing value) then
108    log (item 2 of listDone)'s code() as text
109    log (item 2 of listDone)'s localizedDescription() as text
110    log ocidOutPutString as text
111    return "writeToURL エラーしました"
112  end if
113  ##開く
114  
115  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
116  set boolDone to appSharedWorkspace's openURL:(ocidSaveFilePathURL)
117  if (boolDone) is true then
118    return "openURL 正常処理"
119  else if (boolDone) is false then
120    return "openURL エラーしました"
121  end if
122  
123end open
AppleScriptで生成しました

|

PDF417バーコードを生成する


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

#!/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
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807

#####################
### BarCodコード保存先 NSPicturesDirectory
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidPicturesDirURL to ocidURLsArray's firstObject()
set ocidSaveDirPathURL to ocidPicturesDirURL's URLByAppendingPathComponent:("Barcode")
##フォルダ作成
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
#####################
### ペーストボード初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
##ペーストボードからテキストを取り出す
set ocidStringData to appPasteboard's stringForType:("public.utf8-plain-text")
if ocidStringData is (missing value) then
  set strDefaultAnswer to "https://" as text
else
  set strDefaultAnswer to (refMe's NSString's stringWithString:(ocidStringData)) as text
end if
#####################
###ダイアログ
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 aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns" as alias
try
  set objResponse to (display dialog "URLを入力してください" with title "BarCodコードを作成します" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 30 without hidden answer)
on error
log "エラーしました"
return
end try
if true is equal to (gave up of objResponse) then
return "時間切れですやりなおしてください"
end if
if "OK" is equal to (button returned of objResponse) then
  set strText to (text returned of objResponse) as text
else
return "キャンセル"
end if
#######
set ocidText to refMe's NSString's alloc()'s initWithString:(strText)
###改行とタブだけは取っておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's setString:(ocidText)
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
set strText to ocidTextM as text

if strText starts with "http" then
  set strBarCodContents to strText as text
  set ocidURL to refMe's NSURL's alloc()'s initWithString:(strBarCodContents)
  set strHostName to ocidURL's |host|() as text
else if strText starts with "mailto" then
  set strBarCodContents to strText as text
  set ocidURL to refMe's NSURL's alloc()'s initWithString:(strBarCodContents)
  set ocidComponent to refMe's NSURLComponents's componentsWithURL:(ocidURL) resolvingAgainstBaseURL:(false)
  set strHostName to ocidComponent's |path|() as text
else
  # return "【エラー】URL以外処理しません"
  set strBarCodContents to strText as text
end if
##############################


###保存ファイル名
set strDateNo to doGetDateNo({"yyyyMMddhhmmss", 1})
set strSaveFileName to (strDateNo & ".png") as text
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName)
######################################
### 色決め 切り捨ての都合上指定のニア
######################################
tell application "Finder"
  set the listRGB16bitColor to (choose color default color {0, 0, 0, 1}) as list
end tell
##########Color Picker Value 16Bit
set numRcolor16Bit to item 1 of listRGB16bitColor as number
set numGcolor16Bit to item 2 of listRGB16bitColor as number
set numBcolor16Bit to item 3 of listRGB16bitColor as number
set numAcolor16Bit to 65535 as number
##########Standard RGB Value 8Bit
set numRcolor8Bit to numRcolor16Bit / 256 div 1 as number
set numGcolor8Bit to numGcolor16Bit / 256 div 1 as number
set numBcolor8Bit to numBcolor16Bit / 256 div 1 as number
set numAcolor8Bit to numAcolor16Bit / 256 div 1 as number
##########NSColorValue Float
set numRcolorFloat to numRcolor8Bit / 255 as number
set numGcolorFloat to numGcolor8Bit / 255 as number
set numBcolorFloat to numBcolor8Bit / 255 as number
set numAcolorFloat to numAcolor8Bit / 255 as number
####色指定
## 色指定値はこちらを利用
## https://quicktimer.cocolog-nifty.com/icefloe/2023/06/post-d68270.html
###色指定する場合
## set ocidBarColor to refMe's CIColor's colorWithRed:0.101960784314 green:0.752941176471 blue:0.262745098039 alpha:1.0
###
set ocidBarColor to refMe's CIColor's colorWithRed:(numRcolorFloat) green:(numGcolorFloat) blue:(numBcolorFloat) alpha:(numAcolorFloat)
#############################
### 【1】BarCodバーコード画像生成
#############################
####テキストをNSStringに
set ocidInputString to refMe's NSString's stringWithString:(strBarCodContents)
####テキストをUTF8に
set ocidUtf8InputString to ocidInputString's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
####CIBarCodCodeGenerator初期化
set ocidBarCodeImage to refMe's CIFilter's filterWithName:("CIPDF417BarcodeGenerator")
ocidBarCodeImage's setDefaults()
###テキスト設定
ocidBarCodeImage's setValue:(ocidUtf8InputString) forKey:("inputMessage")
###読み取り誤差値設定L, M, Q, H
ocidBarCodeImage's setValue:(0.5) forKey:("inputCorrectionLevel")

#
ocidBarCodeImage's setValue:(0.5) forKey:("inputCompactionMode")
ocidBarCodeImage's setValue:(0) forKey:("inputAlwaysSpecifyCompaction")
ocidBarCodeImage's setValue:(1) forKey:("inputCompactStyle")
ocidBarCodeImage's setValue:(0) forKey:("inputCompactionMode")
ocidBarCodeImage's setValue:(12) forKey:("inputDataColumns")

ocidBarCodeImage's setValue:(96) forKey:("inputMaxHeight")
ocidBarCodeImage's setValue:(72) forKey:("inputMinHeight")

ocidBarCodeImage's setValue:(288) forKey:("inputMaxWidth")
ocidBarCodeImage's setValue:(72) forKey:("inputMinWidth")
ocidBarCodeImage's setValue:(0.0) forKey:("inputPreferredAspectRatio")
ocidBarCodeImage's setValue:(24) forKey:("inputRows")

###BarCodコード本体のイメージ
set ocidCIImage to ocidBarCodeImage's outputImage()

-->ここで生成されるのはBARのセルがw1pxの最小サイズ
##############
### 色の置き換え
### 置き換わる色=この場合は黒
set ocidBlackColor to refMe's CIColor's colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0
###CIFalseColorで色を塗ります
set ocidFilterColor to refMe's CIFilter's filterWithName:("CIFalseColor")
ocidFilterColor's setDefaults()
ocidFilterColor's setValue:ocidBarColor forKey:("inputColor0")
ocidFilterColor's setValue:ocidBlackColor forKey:("inputColor1")
ocidFilterColor's setValue:ocidCIImage forKey:("inputImage")
###フィルタをかけた画像をoutputImageから取り出します
set ocidCIImage to ocidFilterColor's valueForKey:("outputImage")
###BarCodコードの縦横取得
set ocidCIImageDimension to ocidCIImage's extent()
set ocidCIImageWidth to (item 1 of item 2 of ocidCIImageDimension) as integer
set ocidCIImageHight to (item 2 of item 2 of ocidCIImageDimension) as integer
log ocidCIImageWidth
log ocidCIImageHight
###最終的に出力したいpxサイズ
set numScaleMax to 504
###整数で拡大しないとアレなので↑の値のニアなサイズになります
set numWidthScale to ((numScaleMax / ocidCIImageWidth) div 1) as integer
set numHightScale to ((ocidCIImageHight * numWidthScale) div 1) as integer
log numWidthScale
log numHightScale
###↑サイズの拡大縮小する場合はここで値を調整すれば良い
####変換スケール作成-->拡大
set recordScalse to refMe's CGAffineTransform's CGAffineTransformMakeScale(numWidthScale, numWidthScale)
##変換スケールを適応(元のサイズに元のサイズのスケール適応しても意味ないけど
set ocidCIImageScaled to ocidCIImage's imageByApplyingTransform:(recordScalse)

#######元のセルが1x1pxの最小サイズで出したいときはここで処理
##set ocidCIImageScaled to ocidCIImage
###イメージデータを展開
set ocidNSCIImageRep to refMe's NSCIImageRep's imageRepWithCIImage:(ocidCIImageScaled)
###出力用のイメージの初期化
set ocidNSImageScaled to refMe's NSImage's alloc()'s initWithSize:(ocidNSCIImageRep's |size|())
###イメージデータを合成
ocidNSImageScaled's addRepresentation:(ocidNSCIImageRep)
###出来上がったデータはOS_dispatch_data
set ocidOsDispatchData to ocidNSImageScaled's TIFFRepresentation()
####NSBitmapImageRepに
set ocidBarCodeImageRep to refMe's NSBitmapImageRep's imageRepWithData:(ocidOsDispatchData)
#set numBarCodeRepW to ocidBarCodeImageRep's pixelsWide as integer
#set numBarCodeRepH to ocidBarCodeImageRep's pixelsHigh as integer

#############################
### 【2】BarCodコードの背景部
###(ホワイトスペースパディング配慮)
#############################
##画像サイズ
set numBarCodeSizeW to 520 as integer
set numBarCodeSizeH to 180 as integer
##画像生成開始
set ocidBitmapFormat to refMe's NSBitmapFormatAlphaFirst
set ocidColorSpaceName to refMe's NSCalibratedRGBColorSpace
### NSBitmapImageRep
set ocidCodeBaseRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numBarCodeSizeW) pixelsHigh:(numBarCodeSizeH) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
#############################
### 初期化 CodeBase
refMe's NSGraphicsContext's saveGraphicsState()
###Context
set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidCodeBaseRep))
###生成された画像でNSGraphicsContext初期化
(refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
###ここが背景色の塗り色
##色を個別に指定する場合 値は0が暗 1が明
set ocidSetColor to (refMe's NSColor's colorWithSRGBRed:(1) green:(1) blue:(1) alpha:(1.0))
ocidSetColor's |set|()
###画像生成
refMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:(numBarCodeSizeW), height:(numBarCodeSizeH)}})
####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()
#############################
### 【3】BarCodバーコードパディング処理
### 1で作ったBarCodバーコード画像を
### 2で作った画像にペースト
###(ホワイトスペースパディング配慮)
#############################
###
set numPxWidth to ocidBarCodeImageRep's pixelsWide()
set numPxHight to ocidBarCodeImageRep's pixelsHigh()
###画像合成位置計算パディング配慮
set numPadSize to (numBarCodeSizeW - numPxWidth) / 2 as integer
#############################
### 初期化 CodeBase
refMe's NSGraphicsContext's saveGraphicsState()
###Context
set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidCodeBaseRep))
###生成された画像でNSGraphicsContext初期化
(refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
###出来上がった画像にBarCodバーコードをCompositeSourceOverする
ocidBarCodeImageRep's drawInRect:{origin:{x:(numPadSize), y:(numPadSize)}, |size|:{width:(numPxWidth), Hight:(numPxHight)}} fromRect:{origin:{x:0, y:0}, |size|:{width:(numPxWidth), height:(numPxHight)}} operation:(refMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)

####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()
#############################
### 【4】最終的な出力画像生成
### ArtBoardになる画像の生成
#############################
### 背景 ARTBORD
set ocidBitmapFormat to refMe's NSBitmapFormatAlphaFirst
set ocidColorSpaceName to refMe's NSCalibratedRGBColorSpace
### NSBitmapImageRep
set ocidArtBoardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(580) pixelsHigh:(360) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
#############################
### 初期化 ArtBoard
refMe's NSGraphicsContext's saveGraphicsState()
###Context
set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep))
###生成された画像でNSGraphicsContext初期化
(refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
###ここが背景色の塗り色
##色を個別に指定する場合 値は0が暗 1が明
set ocidSetColor to (refMe's NSColor's colorWithSRGBRed:(numRcolorFloat) green:(numGcolorFloat) blue:(numBcolorFloat) alpha:(numAcolorFloat))
## 透過の場合
## set ocidSetColor to refMe's NSColor's clearColor()
## 白
## set ocidSetColor to refMe's NSColor's whiteColor()
ocidSetColor's |set|()
###画像生成
refMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:(580), height:(680)}})
####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()
#############################
### 【5】BarCodコードペースト
### 3で作ったパディング済みBarCodコードを
### 4で作ったArtBoardにペースト
#############################
### 初期化 バーコードを ocidArtBoardRep にペースト
refMe's NSGraphicsContext's saveGraphicsState()
###ビットマップイメージ
(refMe's NSGraphicsContext's setCurrentContext:(refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep)))
###画像合成位置計算
###左右位置センタリング
set numLeftPad to ((580 - numBarCodeSizeW) / 2) as integer
###左右のパディング幅と同じサイズで上部パディング
set numbottomPad to (680 - numBarCodeSizeW - numLeftPad)
###出来上がった画像にBarCodバーコードを左右3セル分ずらした位置にCompositeSourceOverする
ocidCodeBaseRep's drawInRect:{origin:{x:(numLeftPad), y:(numbottomPad)}, |size|:{width:numBarCodeSizeW, Hight:numBarCodeSizeH}} fromRect:{origin:{x:0, y:0}, |size|:{width:numBarCodeSizeW, height:numBarCodeSizeH}} operation:(refMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()
#############################
### 【6】テキスト描画
### 5で生成された画像に対して
### テキスト画像を描画する
#############################
###フォント初期化
set appFontManager to refMe's NSFontManager
set appSharedMaanager 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 numColorBD to (numRcolorFloat + numGcolorFloat + numBcolorFloat + numAcolorFloat) as number
log numColorBD
if numColorBD > 3.5 then
  ##明るいバーコード色の時は文字色は黒
  set ocidTextColor to (refMe's NSColor's colorWithSRGBRed:(0) green:(0) blue:(0) alpha:(1.0))
(ocidTextAttr's setObject:(ocidTextColor) forKey:(refMe's NSForegroundColorAttributeName))
  ##文字色黒の時はドロップシャドウを入れる
  set ocidShadow to refMe's NSShadow's alloc()'s init()
  set ocidShadowColor to (ocidTextColor's colorWithAlphaComponent:0.8)
(ocidShadow's setShadowColor:(ocidShadowColor))
(ocidShadow's setShadowOffset:(refMe's NSMakeSize(1, -1)))
(ocidShadow's setShadowBlurRadius:4)
(ocidTextAttr's setObject:(ocidShadow) forKey:(refMe's NSShadowAttributeName))
else
  ##暗いバーコード色の時は文字色白
  set ocidTextColor to (refMe's NSColor's colorWithSRGBRed:(1) green:(1) blue:(1) alpha:(1.0))
(ocidTextAttr's setObject:(ocidTextColor) forKey:(refMe's NSForegroundColorAttributeName))
end if

#############################
###初期化
refMe's NSGraphicsContext's saveGraphicsState()
####NSGraphicsContextは透明アートボード
set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep))
###ArtBoardでNSGraphicsContext初期化
(refMe's NSGraphicsContext's setCurrentContext:(ocidContext))
##############
set ocidText to (refMe's NSString's stringWithString:("PDF417Barcode"))
##
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((30), (45))
(ocidText's drawAtPoint:(ocidTextOrigin) withAttributes:(ocidTextAttr))
##############
###URLの文字数調べて
set numCntChar to ((count of (every character of strBarCodContents)) as list) as integer
###
set numFontSize to (round of (24 * (40 / numCntChar)) rounding down) as integer
(*
フォントサイズ24で半角40文字程度入るので
渡されたURLの文字数からフォントサイズを推定 小数点以下は切り捨て
*)
if numFontSize > 24 then
  set numFontSize to 24 as integer
end if
###
set ocidText to (refMe's NSString's stringWithString:(strBarCodContents))
# set ocidFont to (refMe's NSFont's fontWithName:("ヒラギノ角ゴシック W3") |size|:(numFontSize))
##
set ocidFont to (refMe's NSFont's fontWithName:("CourierNewPSMT") |size|:(numFontSize))
(ocidTextAttr's setObject:(ocidFont) forKey:(refMe's NSFontAttributeName))
(ocidTextAttr's setObject:(-1) forKey:(refMe's NSKernAttributeName))
set ocidTextOrigin to refMe's NSMakePoint((35), (15))
(ocidText's drawAtPoint:(ocidTextOrigin) withAttributes:(ocidTextAttr))
(*
ここのキャラクターIDは
こちらを参照してください
https://quicktimer.cocolog-nifty.com/icefloe/cat76056068/index.html
*)
set strIconText to (character id 1049758) as text
set ocidText to (refMe's NSString's stringWithString:(strIconText))
set ocidFont to (refMe's NSFont's fontWithName:("SFPro-Bold") |size|:(72))
(ocidTextAttr's setObject:(ocidFont) forKey:(refMe's NSFontAttributeName))
(ocidTextAttr's setObject:(0) forKey:(refMe's NSKernAttributeName))
set ocidTextOrigin to refMe's NSMakePoint((460), (30))
(ocidText's drawAtPoint:(ocidTextOrigin) withAttributes:(ocidTextAttr))



####画像作成終了
refMe's NSGraphicsContext's restoreGraphicsState()

#############################
### 【7】画像データ保存
### 6で生成された画像に対を
### 指定のフォルダに保存する
#############################
####PNG用の圧縮プロパティ
set ocidNSSingleEntryDictionary to refMe's NSDictionary's dictionaryWithObject:true forKey:(refMe's NSImageInterlaced)
#####出力イメージへ変換
set ocidNSInlineData to (ocidArtBoardRep's representationUsingType:(refMe's NSBitmapImageFileTypePNG) |properties|:ocidNSSingleEntryDictionary)
(*
NSBitmapImageFileTypeJPEG
NSBitmapImageFileTypePNG
NSBitmapImageFileTypeGIF
NSBitmapImageFileTypeBMP
NSBitmapImageFileTypeTIFF
NSBitmapImageFileTypeJPEG2000
*)
### 保存
set ocidOption to (refMe's NSDataWritingAtomic)
set boolDone to ocidNSInlineData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference)
set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias

#############################
### 【8】表示
#############################
###Preview で開く
tell application "Preview"
launch
activate
open file aliasSaveFilePath
end tell
###
#####################
### Finderで保存先を開く
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's selectFile:(ocidSaveFilePathURL's |path|()) inFileViewerRootedAtPath:(ocidSaveDirPathURL's |path|())

return true



################################
# 日付 doGetDateNo(argDateFormat,argCalendarNO)
# argCalendarNO 1 NSCalendarIdentifierGregorian 西暦
# argCalendarNO 2 NSCalendarIdentifierJapanese 和暦
################################
to doGetDateNo({argDateFormat, argCalendarNO})
  ##渡された値をテキストで確定させて
  set strDateFormat to argDateFormat as text
  set intCalendarNO to argCalendarNO as integer
  ###日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義(日本語)
  set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init()
  ###和暦 西暦 カレンダー分岐
  if intCalendarNO = 1 then
    set ocidCalendarID to (current application's NSCalendarIdentifierGregorian)
  else if intCalendarNO = 2 then
    set ocidCalendarID to (current application's NSCalendarIdentifierJapanese)
  else
    set ocidCalendarID to (current application's NSCalendarIdentifierISO8601)
  end if
  set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID)
  set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
  set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX")
  ###設定
ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
ocidFormatterJP's setLocale:(ocidLocaleJP)
ocidFormatterJP's setCalendar:(ocidCalendarJP)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle)
ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle)
  ###渡された値でフォーマット定義
ocidFormatterJP's setDateFormat:(strDateFormat)
  ###フォーマット適応
  set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidDate)
  ###テキストで戻す
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo


---URLエンコードのサブルーチン
####################################
###### %エンコード
####################################
on doUrlEncode(argText)
  ##テキスト
  set ocidArgText to refMe's NSString's stringWithString:(argText)
  ##キャラクタセットを指定
  set ocidChrSet to refMe's NSCharacterSet's URLQueryAllowedCharacterSet
  ##キャラクタセットで変換
  set ocidArgTextEncoded to ocidArgText's stringByAddingPercentEncodingWithAllowedCharacters:(ocidChrSet)
  ######## 置換 %エンコードの追加処理
  ###置換レコード
  set recordPercentMap to {|+|:"%2B", |=|:"%3D", |&|:"%26", |$|:"%24"} as record
  ###ディクショナリにして
  set ocidPercentMap to refMe's NSDictionary's alloc()'s initWithDictionary:(recordPercentMap)
  ###キーの一覧を取り出します
  set ocidAllKeys to ocidPercentMap's allKeys()
  ###取り出したキー一覧を順番に処理
  repeat with itemAllKey in ocidAllKeys
    ##キーの値を取り出して
    set ocidMapValue to (ocidPercentMap's valueForKey:(itemAllKey))
    ##置換
    set ocidEncodedText to (ocidArgTextEncoded's stringByReplacingOccurrencesOfString:(itemAllKey) withString:(ocidMapValue))
    ##次の変換に備える
    set ocidArgTextEncoded to ocidEncodedText
  end repeat
  ##テキスト形式に確定
  set strTextToEncode to ocidEncodedText as text
  ###値を戻す
return strTextToEncode
end doUrlEncode


|

画像のサイズを求める

AppleScriptだとより簡素であることから
NSimageを利用する方法がいいのかな?と

CIImage

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

#!/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 "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 1 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
  
  ##########################
  ####ファイルの数だけ繰り返し
  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 ocidReadData to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidFilePathURL))
    ####################################
    ##サイズ取得 pxサイズ
    set ocidCiImage to (refMe's CIImage's imageWithContentsOfURL:(ocidFilePathURL))
    set ocidPropertiesDict to ocidCiImage's |properties|
    set numPixelsWidth to (ocidPropertiesDict's valueForKey:("PixelWidth"))
    set numPixelsHeight to (ocidPropertiesDict's valueForKey:("PixelHeight"))
log numPixelsWidth as integer
log numPixelsHeight as integer
    
    
  end repeat
end open


NSIMAGE

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

#!/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 "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 1 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
  
  ##########################
  ####ファイルの数だけ繰り返し
  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 ocidReadData to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidFilePathURL))
    ####################################
    ##サイズ取得 Ptサイズ
    #【A】レコードとして取得する
    set recordReadImageSize to ocidReadData's |size|()
    set numPtWidth to (width of recordReadImageSize)
    set numPtHeight to (height of recordReadImageSize)
log numPtWidth as number
log numPtHeight as number
    # 【B】NSConcreteValueとして取得する
    set ocidReadImageSize to ocidReadData's |size|
    #NSConcreteValueの中身によってValue形式を指定する
    set recordReadImageSize to ocidReadImageSize's sizeValue()
    set numPtWidth to (width of recordReadImageSize)
    set numPtHeight to (height of recordReadImageSize)
log numPtWidth as number
log numPtHeight as number
    ####################################
    ##サイズ取得 pxサイズ
    set ocidBmpImageRepArray to ocidReadData's representations()
    set ocidReadImageRep to ocidBmpImageRepArray's firstObject()
    ##
    set numPixelsWidth to ocidReadImageRep's pixelsWide()
    set numPixelsHeight to ocidReadImageRep's pixelsHigh()
log numPixelsWidth as integer
log numPixelsHeight as integer
    
  end repeat
end open


|

[CIImage] QRバーコードのデコード

#!/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 scripting additions

property refMe : a reference to current application

set objFileManager to refMe's NSFileManager's defaultManager()

###################################
#####ダイアログ
###################################a
###ダイアログのデフォルト
set ocidUserDesktopPath to (objFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias
tell application "Finder"
    ##    set aliasDefaultLocation to container of (path to me) as alias
end tell
set listChooseFileUTI to {"public.image"}
set strPromptText to "QRコードファイルを選んでください" as text
set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with invisibles and showing package contents without multiple selections allowed) as list
###################################
#####パス処理
###################################
###エリアス
set aliasFilePath to item 1 of listAliasFilePath as alias
###UNIXパス
set strFilePath to POSIX path of aliasFilePath as text
###String
set ocidFilePath to refMe's NSString's stringWithString:strFilePath
###NSURL
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
####ファイル名から拡張子を取っていわゆるベースファイル名を取得
set ocidPrefixName to ocidFileName's stringByDeletingPathExtension
####コンテナ
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()

###################################
#####保存ダイアログ
###################################
###ファイル名
set strPrefixName to ocidPrefixName as text
###拡張子
###同じ拡張子の場合
##set strFileExtension to ocidFileExtension as text
###拡張子変える場合
set strFileExtension to "txt"
###ダイアログに出すファイル名
set strDefaultName to (strPrefixName & ".output." & strFileExtension) as text
set strPromptText to "名前を決めてください"
###選んだファイルの同階層をデフォルト
set aliasDefaultLocation to ocidContainerDirPathURL as alias
####ファイル名ダイアログ
####実在しない『はず』なのでas «class furl»
set aliasSaveFilePath to (choose file name default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
####UNIXパス
set strSaveFilePath to POSIX path of aliasSaveFilePath as text
####ドキュメントのパスをNSString
set ocidSaveFilePath to refMe's NSString's stringWithString:strSaveFilePath
####ドキュメントのパスをNSURLに
set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath
###拡張子取得
set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text
###ダイアログで拡張子を取っちゃった時対策
if strFileExtensionName is not strFileExtension then
    set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:strFileExtension
end if

###################################
##### イメージファイル読み込み 
###################################
####CIDetectorを定義
set ocidDetector to refMe's CIDetector's detectorOfType:(refMe's CIDetectorTypeQRCode) context:(missing value) options:{CIDetectorAccuracy:(refMe's CIDetectorAccuracyHigh)}
####CIイメージに読み込み
set ocidCiImageInput to (refMe's CIImage's imageWithContentsOfURL:ocidFilePathURL options:(missing value))
####格納用の可変Array
set ocidFeaturesArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
#####ocidDetectorを通して結果をArrayに格納
set ocidFeaturesArray to ocidDetector's featuresInImage:ocidCiImageInput
#####シングルArrayなので1コ目のデータが読み取り結果
set ocidIQRCodeFeature to item 1 of ocidFeaturesArray
#####読み取り結果のテキスト
set ocidQrCodeMessageString to ocidIQRCodeFeature's messageString()


###################################
##### テキストファイルに書き出し
###################################
set boolFileWrite to (ocidQrCodeMessageString's writeToURL:ocidSaveFilePathURL atomically:false encoding:(refMe's NSUTF8StringEncoding) |error|:(reference))


###################################
##### ダイアログ
###################################
set aliasIconPath to POSIX file "/System/Library/CoreServices/Applications/Wireless Diagnostics.app/Contents/Resources/AppIcon.icns" as alias
set strDefaultAnswer to ocidQrCodeMessageString as text
try
    set recordResponse to (display dialog "コピーしてください" with title "QRコード読み取り結果" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 30 without hidden answer)
    
on error
    log "エラーしました"
    return "エラーしました"
    error number -128
end try
if true is equal to (gave up of recordResponse) then
    return "時間切れですやりなおしてください"
    error number -128
end if
if "OK" is equal to (button returned of recordResponse) then
    set theResponse to (text returned of recordResponse) as text
else
    log "エラーしました"
    return "エラーしました"
    error number -128
end if



|

[CIImage]画像のリサイズ

#!/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 scripting additions

property listChooseFileUTI : {"public.png", "public.jpeg"}
property numScaleMaxWidth : 720

property refMe : a reference to current application
set objFileManager to refMe's NSFileManager's defaultManager()

###################################
#####スクリーンキャプチャーの保存先
###################################

####設定ファイルのパス
set strFilePath to "~/Library/Preferences/com.apple.screencapture.plist" 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
#####PLISTの内容を読み込んで
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set listReadPlistData to refMe's NSMutableDictionary's dictionaryWithContentsOfURL:ocidFilePathURL |error|:(reference)
set ocidPlistDict to item 1 of listReadPlistData
#####保存先を調べる
set ocidValue to ocidPlistDict's valueForKey:"location"
#####設定されていない場合はデスクトップがデフォルト
if ocidValue is (missing value) then
    set strLocationPath to "~/Desktop" as text
    set ocidLocationPathStr to refMe's NSString's stringWithString:strLocationPath
    set ocidLocationPath to ocidLocationPathStr's stringByStandardizingPath
    set ocidLocationPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidLocationPath isDirectory:false
else
    #####設定されている場合は設定先のパス
    set ocidLocationPath to ocidValue's stringByStandardizingPath
    set ocidLocationPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidLocationPath isDirectory:true
end if
set ocidPlistDict to ""
#####
###################################
#####ダイアログ
###################################
set aliasDefaultLocation to ocidLocationPathURL as alias
set strPromptText to "ファイルを選んでください" as text
set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents)

repeat with objAliasFilePath in listAliasFilePath
    set strFilePath to POSIX path of objAliasFilePath as text
    set ocidFilePath to (refMe's NSString's stringWithString:strFilePath)
    set itemImageFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath)
    
    ###################################
    ##### 幅を揃えてリサイズする
    ###################################
    (*
    Base Script 
    https://www.macscripter.net/t/resizing-an-image/73317
    
    *)
    ###種別判定用に拡張子取得
    set ocidExtensionName to itemImageFilePathURL's pathExtension()
    set ocidExtensionName to ocidExtensionName's lowercaseString()
    set strExtensionName to ocidExtensionName as text
    ####ファイルをCIイメージで読み込み
    set ocidCiImageInput to (refMe's CIImage's imageWithContentsOfURL:itemImageFilePathURL options:(missing value))
    ###ファイルのサイズを調べる
    set ocidInputDimension to ocidCiImageInput's extent()
    ####幅の値を取得
    set numImageWidth to (item 1 of (item 2 of ocidInputDimension)) as integer
    ####リサイズする指数
    set numResizeScale to (numScaleMaxWidth / numImageWidth)
    ####Transform指定
    set recordCiImageData to (ocidCiImageInput's imageTransformForOrientation:(refMe's kCGImagePropertyOrientationUp))
    ####Transform適応
    set ocidCiImageData to (ocidCiImageInput's imageByApplyingTransform:recordCiImageData)
    ####リサイズする指数でリサイズ
    set ocidCiFilterData to (refMe's CIFilter's filterWithName:"CILanczosScaleTransform" withInputParameters:{inputImage:ocidCiImageData, inputScale:numResizeScale, inputAspectRatio:1.0})
    #####リサイズ済みイメージ
    set ocidResizedCiImage to ocidCiFilterData's outputImage()
    #####NSBitmapImageRepに変換して
    set ocidResizedImagePep to (refMe's NSBitmapImageRep's alloc()'s initWithCIImage:ocidResizedCiImage)
    
    if strExtensionName is "png" then
        ####PNGの保存オプション
        set recordSaveProperties to {NSImageInterlaced:true}
        ####PNG変換
        set ocidOsDispatchData to (ocidResizedImagePep's representationUsingType:(refMe's NSBitmapImageFileTypePNG) |properties|:recordSaveProperties)
        ####上書き保存
        set boolResults to (ocidOsDispatchData's writeToURL:itemImageFilePathURL atomically:true)
    else
        ####JPGの保存オプション
        set ocidSavePropertiesDict to (refMe's NSDictionary's alloc()'s initWithDictionary:{NSImageCompressionFactor:1, NSImageProgressive:false})
        ####JPG変換
        set ocidOsDispatchData to (ocidResizedImagePep's representationUsingType:(refMe's NSBitmapImageFileTypeJPEG) |properties|:ocidSavePropertiesDict)
        ####上書き保存
        set boolResults to (ocidOsDispatchData's writeToURL:itemImageFilePathURL atomically:true)
    end if
    
    if boolResults is true then
        log "処理OK"
    else
        log "処理NGなのでそのままにする"
        set boolResults to (ocidImageFilePathURL's setResourceValue:6 forKey:(refMe's NSURLLabelNumberKey) |error|:(reference))
        log "失敗ラベル赤を塗る"
    end if
    set ocidImageData to ""
    set ocidResizedImagePep to ""
    set ocidOsDispatchData to ""
end repeat

|

その他のカテゴリー

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