Resize and crop photos to put on a digital frame

Lorenzo Baloci Lorenzo Baloci
26 Feb 2009

Introduction

If you have a digital frame you may find this page useful. The apple script listed here takes an arbitrary number of images, crop and resize them to fit nicely on your digital frame. You don't need to worry about picture ratio (4:3, 3:2, etc.) but just modify the script parameters that define your digital frame resolution.

Downloads

You can download the example source script and compile it by yourself.
Or you can also download an intel pre-compiled version with variables set at 800x600.

The script

Here it the source:
-- save in Script Editor as Application
-- drag files to its icon in Finder

on open some_items
	repeat with this_item in some_items
		try
			rescale_and_save(this_item)
		end try
	end repeat
end open


to rescale_and_save(this_item)
	tell application "Image Events"
		set target_height to 600
		set target_width to 800
		launch
		-- open the image file
		set this_image to open this_item

		set typ to this_image's file type

		copy dimensions of this_image to {current_width, current_height}
		if current_height is greater than current_width then
			scale this_image to size target_height
		else
			-- figure out new height
			-- y2 = (y1 * x2) / x1
			set the new_width to (current_width * target_height) / current_height
			scale this_image to size new_width
		end if

		copy dimensions of this_image to {current_width, current_height}

		if current_width is not target_width then
			if current_height is less than current_width then
				crop this_image to dimensions {target_width, target_height}
			end if
		end if

		tell application "Finder" to set new_item to ¬
			(container of this_item as string) & "scaled." & (name of this_item)
		save this_image in new_item as typ

	end tell
end rescale_and_save
just edit the variables "target_height" and "target_width" to reflect your digital frame resolution and your good to go!



This article is made from personal notes and is not intended to be a comprehensive tutorial, you can indeed find more information about each subjects on the web.