use scripting additionsuse framework "Foundation"
use framework "AppKit"
set thePicture to (path to desktop as text) & "créer clé El Capitan.jpeg"
my convertPictureFileAt:{POSIX path of thePicture, "jpg"}
on convertPictureFileAt:{posixPath, destExt} # may be "png" or "jpg"
-- build new path
if (posixPath ends with ("." & destExt)) or (posixPath ends with ".jpeg" and destExt is "jpg") then
error posixPath & " is already a ." & destExt & " file !"
else
set oldPath to current application's NSString's stringWithString:posixPath
set newPath to oldPath's stringByDeletingPathExtension()'s stringByAppendingPathExtension:destExt # EDITED
-- make NSImage from file
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:oldPath
-- get TIFF version as data
set theData to theImage's TIFFRepresentation()
-- make bitmap representation from TIFF data
set bitmapImageRep to current application's NSBitmapImageRep's imageRepWithData:theData
-- extract jpeg representation from bitmap
if destExt = "png" then
set theData to bitmapImageRep's representationUsingType:(current application's NSPNGFileType) |properties|:{NSImageCompressionFactor:1.0} -- between 0.0 and 1.0
else
set theData to bitmapImageRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:1.0} -- between 0.0 and 1.0
end if
--save to file
theData's writeToFile:newPath atomically:true
end if
end convertPictureFileAt:
Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) lundi 17 août 2015 23:05:33