[NSimage]イメージ変換
少し修正した
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#error number -128
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
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 refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL
set aliasDefaultLocation to path to desktop folder from user domain
set listChooseFiles to (choose file with prompt "ファイルを選んでください" default location aliasDefaultLocation of type {"public.image"} with invisibles and multiple selections allowed without showing package contents) as list
repeat with objFile in listChooseFiles
set theFilePath to POSIX path of objFile
-->text
set ocidFilePath to (refNSString's stringWithString:theFilePath)
-->(*__NSCFString*)
set ocidFullPathURL to (refMe's NSURL's fileURLWithPath:ocidFilePath)
-->(*NSURL*)
#####拡張子を取って
set ocidBaseFilePathURL to ocidFullPathURL's URLByDeletingPathExtension()
-->(*NSURL*)
######新しい拡張子を加える
set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:"jpeg")
-->(*NSURL*)
(*
set ocidFileName to ocidFullPathURL's lastPathComponent
-->(*NSPathStore2*)ファイル名
set ocidPrefixName to ocidFileName's stringByDeletingPathExtension
-->(*NSPathStore2*)ファイル名から拡張子を取ったいわゆるベースファイル名
set ocidFileExtension to ocidFilePath's pathExtension
-->(*NSPathStore2*)拡張子
set ocidContainDirPath to ocidFilePath's stringByDeletingLastPathComponent
-->(*NSPathStore2*)元ファイルのあるディレクトリ
set ocidSaveFileName to (ocidPrefixName's stringByAppendingString:".jpeg")
-->(*__NSCFString*)ベースファイル名に拡張子を追加して書き出しファイル名
set ocidSaveFilePath to (ocidContainDirPath's stringByAppendingPathComponent:ocidSaveFileName)
-->(*NSPathStore2*)コンテナディレクトリにファイル名を足して保存先
####ファイルパスのテキスト
set strSaveFilePath to ocidSaveFilePath as text
-->text ファイルパスをテキストで確定させて
set ocidSaveFilePath to (refMe's NSURL's fileURLWithPath:strSaveFilePath)
*)
-->(*NSURL*) NSURLを作り直し
###イメージデータ展開
set ocidImageRep to (refMe's NSBitmapImageRep's imageRepWithContentsOfFile:theFilePath)
####NSImageColorSyncProfileData
set ocidColorSpace to refMe's NSColorSpace's displayP3ColorSpace()
set ocidColorSpaceData to ocidColorSpace's colorSyncProfile()
####NSImageEXIFData
set ocidEXIFData to (ocidImageRep's valueForProperty:(refMe's NSImageEXIFData))
####NSImageFallbackBackgroundColor
set ocidBackGroundColor to (refMe's NSColor's colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:1.0)
####propertiesデータレコード整形
set ocidImageProperties to {NSImageCompressionFactor:0.0, NSImageProgressive:0, NSImageFallbackBackgroundColor:ocidBackGroundColor, NSImageEXIFData:ocidEXIFData, NSImageColorSyncProfileData:ocidColorSpaceData} as record
(*
NSImageEXIFData
NSImageProgressive
NSImageColorSyncProfileData
NSImageCompressionFactor
NSImageFallbackBackgroundColor
NSImageGamma
NSImageInterlaced
NSImageFrameCount
NSImageCurrentFrameDuration
NSImageCompressionMethod
NSImageDitherTransparency
NSImageLoopCount
NSImageCurrentFrame
NSImageRGBColorTable
*)
#####JPEGデータに変換
set ocidSaveData to (ocidImageRep's representationUsingType:(refMe's NSBitmapImageFileTypeJPEG) |properties|:ocidImageProperties)
(*
NSBitmapImageFileTypeTIFF
NSBitmapImageFileTypeBMP
NSBitmapImageFileTypeGIF
NSBitmapImageFileTypeJPEG
NSBitmapImageFileTypePNG
NSBitmapImageFileTypeJPEG2000
*)
tell ocidImageRep
log bitsPerSample()
#####
log pixelsHigh()
log pixelsWide()
#####
log pixelsHigh()
log pixelsWide()
#####
log bitsPerPixel()
log bytesPerPlane()
log bitmapFormat()
log samplesPerPixel()
log hasAlpha()
log isOpaque()
log isPlanar()
log layoutDirection()
log colorSpaceName()
end tell
####ファイル書き出し
(*
set boolWroteToFileDone to (ocidSaveData's writeToFile:strSaveFilePath atomically:true)
log boolWroteToFileDone as boolean
*)
(*
set ocidWroteToFileDone to ocidSaveData's writeToURL:ocidSaveFilePath options:0
*)
(*
set ocidWroteToFileDone to (ocidSaveData's writeToFile:ocidSaveFilePath options:0 |error|:(reference))
log item 1 of ocidWroteToFileDone
log item 2 of ocidWroteToFileDone
*)
set ocidWroteToFileDone to (ocidSaveData's writeToURL:ocidSaveFilePathURL options:0 |error|:(reference))
log item 1 of ocidWroteToFileDone
log item 2 of ocidWroteToFileDone
(*
options
NSDataWritingAtomic:0
NSDataWritingWithoutOverwriting:1
NSDataWritingFileProtectionNone:0x10000000
NSDataWritingFileProtectionComplete:0x20000000
NSDataWritingFileProtectionCompleteUnlessOpen:0x30000000
NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication:0x40000000
NSDataWritingFileProtectionMask:0xf0000000
*)
###releaseすると…クラッシュするんだよねぇ
##ocidSaveData's release()
##ocidImageRep'S release()
set ocidSaveData to ""
set ocidImageRep to ""
end repeat
| 固定リンク
「NSImage」カテゴリの記事
- [NSIMAGE]ピクセルサイズはそのままポイントサイズを半分にして144ppiにする(2024.12.06)
- [NSImageRep] 画像の解像度(ピクセル密度)を取得する(2024.06.10)
- 画像の解像度だけ変更する(2024.02.24)
- [NSImage]画像の解像度変更(2023.02.24)
- [NSimage] イメージデータをPDFに変換(2023.01.27)