« [CURL]CRLとしてコピーしたURLをURLとヘッダーに分離する | トップページ | [gif2webp]GIFアニメをwebpに変換する »

[img2webp]アニメーションwebpの作成


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(* libwebpが別途必要です
[applescript]libwebpインストール
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-0a1a86.html
*)
# 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 strImg2webpPath to ("~/bin/libwebp/bin/img2webp") as text
set strWebpinfoPath to ("~/bin/libwebp/bin/webpinfo") as text

###【設定項目】コマ間隔 1000=1秒
# (8コマ=125 10コマ=100 16コマ≒62 32コマ≒31)
set numDuration to 125 as number

###img2webpパス
set ocidBinPathStr to refMe's NSString's stringWithString:(strImg2webpPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strImg2webpPath to ocidBinPath as string
###webpinfoパス
set ocidBinPathStr to refMe's NSString's stringWithString:(strWebpinfoPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strWebpinfoPath to ocidBinPath as string

###ダイアログを前面に
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
tell application "Finder"
  set aliasDesktopFolder to (path to desktop folder from user domain) as alias
end tell
####ファイル選択ダイアログ
set listAliasFilePath to (choose file with prompt "ファイルを選んでください" default location aliasDesktopFolder of type {"public.png"} with invisibles and multiple selections allowed without showing package contents) as list

###並び替え用のアレーの初期化
set ocidFilePathArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:0
###選択したファイルパスをUNIXファイルパスに変換してリストに格納
repeat with itemAliasFilePath in listAliasFilePath
  set aliasFilePath to itemAliasFilePath as alias
  set strFilePath to (POSIX path of aliasFilePath) as text
(ocidFilePathArrayM's addObject:(strFilePath))
end repeat
####ファイルパスを名前順に並び替え
set ocidSortedArray to ocidFilePathArrayM's sortedArrayUsingSelector:("localizedStandardCompare:")
set numCntImage to (count of ocidSortedArray) as integer
###
#######
###ディレクトリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
###
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 strTempPath to ocidSaveDirPathURL's |path| as text
set strSaveFilePath to (strTempPath & "/animetion.webp") as text

############################
####コマンド行の初期化
############################
set strCommandText to ("") as text
repeat with itemSortedArray in ocidSortedArray
  set strFilePath to itemSortedArray as text
  ###コマンド行【入力ファイル部分】を整形して
  set strAddCommandText to ("-lossless -d " & numDuration & " -q 100 \"" & strFilePath & "\"") as text
  set strCommandText to (strCommandText & " " & strAddCommandText) as text
end repeat
############################
###コマンド行 出力部
############################
set strCommandText to ("\"" & strImg2webpPath & "\" " & strCommandText & " -o \"" & strSaveFilePath & "\"") as text
do shell script strCommandText
############################
###コマンドWebpinfo部
############################
set strCommandText to ("\"" & strWebpinfoPath & "\" \"" & strSaveFilePath & "\" | grep \"Canvas size\" | tr -d \"Canvas size\"") as text
set strResponse to (do shell script strCommandText) as text
############################
###コマンド行 Ditto部
############################
set strNewFileName to ("animation_" & numCntImage & "_" & strResponse & ".webp") as text
set strDesktopFolder to (POSIX path of aliasDesktopFolder) as text
set strDittoFilePath to (strDesktopFolder & strNewFileName) as text
set strCommandText to ("/usr/bin/ditto \"" & strSaveFilePath & "\" \"" & strDittoFilePath & "\"") as text
do shell script strCommandText




旧バージョン

#!/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
property refNSString : a reference to refMe's NSString
property refNSMutableArray : a reference to refMe's NSMutableArray

###コマ間隔 1000=1
set numDuration to 1000 as number
###出力ファイル名
set strOutPutFileName to "AnimatedWebp.webp"
###img2webpへのパス
set strCommandText to ("$HOME/bin/libwebp/bin/img2webp -loop 0 ") as text


tell application "Finder"
set aliasDefaultLocation to container of (path to me) as alias
set aliasDesktopFolder to (path to desktop folder from user domain) as alias
end tell
set strDesktopFolderPath to POSIX path of aliasDesktopFolder as text

###デスクトップに出力
set strOutPutFilePath to ("" & strDesktopFolderPath & strOutPutFileName & "") as text


####ファイル選択ダイアログ
set listChooseFile to (choose file with prompt "フォントファイルを選んでください" default location aliasDefaultLocation of type {"public.png"} with invisibles and multiple selections allowed without showing package contents) as list

###並び替え用のアレーの初期化
set ocidNewArrayM to refNSMutableArray's alloc()'s initWithCapacity:0

###選択したファイルパスをUNIXファイルパスに変換してリストに格納
repeat with objFilePath in listChooseFile
set aliasFilePath to objFilePath as alias
set strFilePath to POSIX path of aliasFilePath as text
(ocidNewArrayM's addObject:strFilePath)
end repeat

####ファイルパスを名前順に並び替え
set ocidSelf to refNSString's stringWithString:"self"
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:ocidSelf ascending:true selector:"compare:"
set ocidSortedList to (ocidNewArrayM's sortedArrayUsingDescriptors:{ocidDescriptor}) as list

####コマンド行の初期化
set strAddCommandText to ""
###ファイルパスだけ繰り返し
repeat with objFilePath in ocidSortedList
###テキストにして
set strFilePath to objFilePath as text
###コマンド行を整形して
set strAddCommandText to " -lossless -d " & numDuration & " -q 100 \"" & strFilePath & "\"" as text
###コマンド行に追加
set strCommandText to strCommandText & strAddCommandText as text

end repeat

####最終的なコマンド行を整形して
set strCommandText to ("" & strCommandText & " -o \"" & strOutPutFilePath & "\"") as text

###実行
tell application "Terminal"
launch
activate
set objWindowID to (do script "\n\n")
delay 2
do script strCommandText in objWindowID
end tell

|

« [CURL]CRLとしてコピーしたURLをURLとヘッダーに分離する | トップページ | [gif2webp]GIFアニメをwebpに変換する »

webp」カテゴリの記事