SVG画像のサイズを求める
#!/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
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.svg-image"}
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 listReadData to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(refMe's NSXMLNodeOptionsNone) |error|:(reference))
set ocidXmlDoc to (item 1 of listReadData)
#ROOTエレメントを取得して
set ocidRootElement to ocidXmlDoc's rootElement
#viewBoxを取得
set ocidViewBox to (ocidRootElement's attributeForName:("viewBox"))
#テキストにして
set ocidViewBoxStr to ocidViewBox's stringValue()
#スペースを区切り文字でリストにして
set ocidViewBoxArray to (ocidViewBoxStr's componentsSeparatedByString:(" "))
#3番目と4番目が横縦ピクセルサイズ
set ocidPixelWidth to (ocidViewBoxArray's objectAtIndex:(2))
set ocidPixelHeight to (ocidViewBoxArray's objectAtIndex:(3))
log ocidPixelWidth as integer
log ocidPixelHeight as integer
end repeat
end open
| 固定リンク
「XML SVG」カテゴリの記事
- [pymupdf]SVG to PDF(個別フォントをロードしないので文字のあるSVG向きではない)(2025.01.10)
- [Keynote]Keynoteを使ってSVGを画像にする(仮)(2024.12.06)
- [SVG]SVGの縦横pxサイズに取得(2024.03.14)
- SVGの縦横サイズの取得(SVGZ対応)(2024.03.13)
- SVGイメージのEpubフォルダを生成する(2024.03.09)