Created
May 13, 2011 18:01
-
-
Save timvisher/971002 to your computer and use it in GitHub Desktop.
image scaler that works on the current selection in Finder.app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "Finder" to set wallpapers to selection | |
set myDimensions to {w169:[{2560, 1440}, {1920, 1080}, {1366, 768}], w1610:[{2560, 1600}, {1920, 1200}, {1440, 900}, {1280, 800}], f43:[{1600, 1200}], s:[{1024, 1024}]} | |
tell application "Image Events" | |
repeat with currentWallpaper in wallpapers | |
set theWallpaper to open (currentWallpaper as alias) | |
tell theWallpaper | |
set theWallpaperDimensions to dimensions of theWallpaper | |
set theWallpaperAspectRatio to (item 1 of theWallpaperDimensions) / (item 2 of theWallpaperDimensions) | |
if 16 / 10 is equal to theWallpaperAspectRatio then set currentAspects to w1610 of myDimensions | |
if 16 / 9 is equal to theWallpaperAspectRatio then set currentAspects to w169 of myDimensions | |
if 4 / 3 is equal to theWallpaperAspectRatio then set currentAspects to f43 of myDimensions | |
if 1 is equal to theWallpaperAspectRatio then set currentAspects to s of myDimensions | |
repeat with dim in currentAspects | |
-- Scale and Crop to current dimensions | |
if item 1 of theWallpaperDimensions is greater than item 1 of dim then | |
scale to size (get item 1 of dim) | |
-- Set up save target | |
set namePrefix to text items 1 thru ((offset of "." in (get name)) - 1) of (get name) as string | |
tell application "Finder" | |
set _ to parent of currentWallpaper as alias | |
set parentPath to POSIX path of _ | |
end tell | |
set saveTarget to parentPath & namePrefix & "_" & (get item 1 of dim) & "x" & (get item 2 of dim) & ".jpg" | |
--save to target | |
save in saveTarget as JPEG | |
end if | |
end repeat | |
end tell | |
end repeat | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment