[NSimages]画像の解像度ppiを求める
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
######ログ表示
doLogView()
property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSMutableString : a reference to refMe's NSMutableString
property refNSURL : a reference to refMe's NSURL
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807
property refNSImage : a reference to refMe's NSImage
set objFileManager to refMe's NSFileManager's defaultManager()
set strFilePath to "/System/Library/Desktop Pictures/Big Sur Graphic.heic"
##Make NSString
set ocidNSString to refNSString's stringWithString:strFilePath
log ocidNSString as text
log ocidNSString's className() as text
####NSimageに格納
set ocidImageData to refNSImage's alloc()'s initWithContentsOfFile:strFilePath
log ocidImageData
log className() of ocidImageData as text
###サイズ取得PT
set ocidImageSize to ocidImageData's |size|()
log ocidImageSize
log class of ocidImageSize as text
log "#####"
###representations取得
set ocidImageRepArray to ocidImageData's representations()
log ocidImageRepArray
log className() of ocidImageRepArray as text
###NSBitmapImageRep取得
set ocidImageRep to (ocidImageRepArray's objectAtIndex:0)
log ocidImageRep
log className() of ocidImageRep as text
####ピクセル単位での幅
set numpixelsWidth to ocidImageRep's pixelsWide()
log numpixelsWidth
log class of numpixelsWidth as text
####ピクセル単位での高さ
set numpixelsHeight to ocidImageRep's pixelsHigh()
log numpixelsHeight
log class of numpixelsHeight as text
####ポイント単位でのサイズ
set ocidImageRepSize to ocidImageRep's |size|()
log ocidImageRepSize
log class of ocidImageRepSize as text
####ポイント単位での幅と高さ
set numPointWidth to width of ocidImageRepSize
set numPointHeight to height of ocidImageRepSize
log numPointWidth
log numPointHeight
####イメージの解像度
set numCurrentDPI to ((72 * numpixelsWidth) / numPointWidth) as integer
log numCurrentDPI
#########################ログ表示
to doLogView()
tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
tell application "Script Editor"
tell application "System Events"
tell process "Script Editor"
tell window 1
tell splitter group 1
tell splitter group 1
tell group 1
tell checkbox "返された値"
set boolValue to value as boolean
end tell
if boolValue is false then
click checkbox "返された値"
end if
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end if
end repeat
end doLogView
#########################
| 固定リンク
「NSImage」カテゴリの記事
- [NSImageRep] 画像の解像度(ピクセル密度)を取得する(2024.06.10)
- 画像の解像度だけ変更する(2024.02.24)
- [NSImage]画像の解像度変更(2023.02.24)
- [NSimage] イメージデータをPDFに変換(2023.01.27)
- [NSimage]イメージ変換(2022.10.12)