Page 1 of 1

Resize and Watermark Script?

Posted: 2011-10-24T11:59:12-07:00
by markinhifi
I want to create an Applescript that will resize and watermark a bunch of images using ImageMagick. I realize that I have to create a shell script (or something) within the Applescript to get this to work, that's fine, I just want ONE droplet that will do all of this automatically.

I know nothing about any of this and have spent days trying to piece something together that works. My existing script was just a re-sizer which didn't utilize ImageMagick. I want to combine that script plus a watermarking script that uses IM. However, i'd also be open to using IM to resize the image as well, if that's easier to figure out.

This is my re-sizer.

Code: Select all

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"
		launch
		set the target_width to 640
		-- 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_width is greater than current_height then
			scale this_image to size target_width
		else
			-- figure out new height
			-- y2 = (y1 * x2) / x1
			set the new_height to (current_height * target_width) / current_width
			scale this_image to size new_height
		end if
		
		tell application "Finder" to set new_item to ¬
			(container of this_item as string) & "s_" & (name of this_item)
		save this_image in new_item as typ
		
	end tell
end rescale_and_save
And this is my watermarking script which i've found online and can't get to work.

Code: Select all

on open theObjects
    repeat with theObject in theObjects
        do shell script "/opt/local/bin/composite -compose Over " & �
        "-gravity southwest /Users/airborne/Pictures/copyright.gif '" & �
        (POSIX path of theObject as string) & "' '" & (POSIX path of theObject as string) & "'"
    end repeat
end open  
Any suggestions? In all honesty, i'd be happy to pay someone a few dollars via PayPal to just write this thing for me. I've spent 20+ hours trying to figure this out already and i'm sure someone who actually knows how can execute this in 5 minutes. Can anybody help me?

Re: Resize and Watermark Script?

Posted: 2011-10-24T14:28:34-07:00
by fmw42
First you need to find out if your problem is with IM or Applescript. Can you do a composite with one image and get that to work via command line typing at the terminal? The other approach is to write a shell script to do everything and then just call the shell script via Applescript.

on open theObjects
repeat with theObject in theObjects
do shell script "/opt/local/bin/composite -compose Over " & �
"-gravity southwest /Users/airborne/Pictures/copyright.gif '" & �
(POSIX path of theObject as string) & "' '" & (POSIX path of theObject as string) & "'"
end repeat
end open
I think the " do shell script" usually calls a unix shell script and not the IM commands. So put your command in a bash shell script and then call the script from the do shell script.

It has been too long for me since I wrote Applescripts and have never combined them with IM commands, so I may be wrong about the above.

Is your copywrite a fixed image or will it change? Do you just want to be able to drop one image onto the Applescript and have it overlay your copyright? Is your copyright transparent or not? Do any of your image names have spaces in them, if so, then the file must be quoted. So you must be careful about quotes within quotes in your applescript. Is your IM actually in /opt/local/bin/ --- have you verified that?