« [Basic]MimeTypeとUTI | トップページ | [NSBitmapImageRep]画像のサイズ変更(CROP) »

[Resolution]解像度を求める

たぶん、もっとスマートな方法があるに違いない

#!/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 objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSImage : a reference to NSImage
property objNSBitmapImageRep : a reference to NSBitmapImageRep

######ログ表示
doLogView()
###動作確認している分だけ
set listUTI to {"public.jpeg", "public.png", "org.webmproject.webp", "public.heic", "public.bmp"}
###ダイアログのデフォルトロケーション
tell application "Finder"
## set aliasDefaultLocation to container of (path to me) as alias
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
end tell

###ダイアログ
set aliasFile to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias

###エイリアスをUNIXパスに
set strFilePath to POSIX path of aliasFile as text

####NSBitmapImageRepの処理
set ocidBitmapImageRepObj to (objNSBitmapImageRep's imageRepWithContentsOfFile:strFilePath)
###
set numImageRepHight to ocidBitmapImageRepObj's pixelsHigh() as integer
###
set numImageRepWide to ocidBitmapImageRepObj's pixelsWide() as integer
####ピクセル数
set numImageRepBytePerPlane to (numImageRepHight * numImageRepWide) as integer

log numImageRepHight
log numImageRepWide
log numImageRepBytePerPlane
#####NSImageの処理
set ocidNSImageFileObj to (objNSImage's alloc()'s initWithContentsOfFile:strFilePath)
set recordSize to (ocidNSImageFileObj's |size|()) as record
###
set numNSImageHeight to height of recordSize as integer
###
set numNSImageWidth to width of recordSize as integer
####ピクセル数
set numNSImageBytePerPlane to (numNSImageHeight * numNSImageWidth) as integer
log numNSImageHeight
log numNSImageWidth
log numNSImageBytePerPlane
####解像度を求める
set numResolution to (((numImageRepBytePerPlane / numNSImageBytePerPlane) ^ 0.5) * 72) as integer


log numResolution





#########################ログ表示
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
end if
end repeat

end doLogView
#########################

|

« [Basic]MimeTypeとUTI | トップページ | [NSBitmapImageRep]画像のサイズ変更(CROP) »

AppleScript Image Events」カテゴリの記事

AppleScript NSImage」カテゴリの記事

AppleScript NSBitmapImageRep」カテゴリの記事