Image Events: Duplicate and resize thumbnail?

Hello guys ,
I am new in applescript.But it seems to be very powerfull!
I am trying to do the following:

  • choose a folder
  • scan folder for images
  • duplicate each image and resize the duplicated image in a thumbnail.
  • move the duplicated and resized image in a folder name (thumb)
    Can any one help me with the part of the script to :
  • duplicate the file?
    -resize the file (with resolution: 30 width:80)
    -move the file in ‘thumb’ folder

thank you very much

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct"}

tell application "Finder"
	try
		set the source_folder to choose folder with prompt ¬
			"Pick a folder containing the images to process:"
		set these_files to every file of the source_folder whose ¬
			file type is in the type_list or name extension is in the extension_list
		-- creating  folder
		--if not (exists folder "large" at source_folder of this_disk) then
		make new folder at source_folder with properties {name:"thumb"}
		-- end creating  folder
		repeat with i from 1 to the count of these_files
			set this_path to (item i of these_files) as string
			set item_name to (the name of item i of these_files) as string
			-- create new path to put image
			set new_folder to (source_folder & "large") as string
			set new_path to (source_folder & "large:" & item_name) as string

			--duplicate this_path to new_folder
			tell application "Image Events"
				set this_image to open file this_path
				-- IMAGE PROCESSING STATEMENTS GO HERE
				close this_image
			end tell
			-- FINDER ACTIONS SUCH AS MOVE, DUPLICATE, OR DELETE GO HERE
		end repeat
	on error error_message
		display dialog error_message buttons {"OK"} default button 1
	end try
end tell

Hi, John. I think this does what you want. It duplicates each image file to the “thumb” folder and creates the scaled image files there too under modified names. (I’ve assumed that “thumb” and “large” are supposed to be the same folder. :slight_smile: ) I couldn’t find a way to change the ‘resolution’ of the images.

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct"}

try
	tell application "Finder"
		set the source_folder to choose folder with prompt ¬
			"Pick a folder containing the images to process:"
		set these_files to every file of the source_folder whose ¬
			file type is in the type_list or name extension is in the extension_list
		-- Create the "thumb" folder if it doesn't exist.
		if (folder "thumb" of source_folder exists) then
			set thumb_folder to folder "thumb" of source_folder
		else
			set thumb_folder to (make new folder at source_folder with properties {name:"thumb"})
		end if
		
		repeat with i from 1 to the count of these_files
			-- Get the path to this image file.
			set this_path to (item i of these_files) as Unicode text
			-- Duplicate the file to the "thumb" folder and get the path to the result.
			set new_path to (duplicate file this_path to thumb_folder with replacing) as Unicode text
			
			-- Doctor the new path to derive a path for the thumbnail image. (" (thumb)" inserted in name.)
			set astid to AppleScript's text item delimiters
			set AppleScript's text item delimiters to "."
			set new_path to text 1 thru text item -2 of new_path & " (thumb)." & text item -1 of new_path
			set AppleScript's text item delimiters to astid
			
			-- Process the image in a separate handler. (It's best not to nest application 'tell' blocks if it can be avoided.)
			my process_image(this_path, new_path)
		end repeat
	end tell
on error error_message
	display dialog error_message buttons {"OK"} default button 1
end try
tell application "Image Events" to quit

on process_image(source_path, destination_path)
	tell application "Image Events"
		activate
		set this_image to (open alias source_path)
		-- Scale the image to width 80.
		-- (I don't think the resolution can be set.)
		scale this_image to size 80
		-- Save the scaled image directly to the "thumb" folder under the doctored name.
		save this_image as JPEG in file destination_path
		close this_image
	end tell
end process_image