Re: Image events: How do I cut out a region
Re: Image events: How do I cut out a region
- Subject: Re: Image events: How do I cut out a region
- From: Skeeve <email@hidden>
- Date: Tue, 15 Apr 2008 21:08:28 +0200
Pat Cannon wrote:
Sorry to have wasted your time.
It's not you who wasted my time, it's the thousands of replies, similar
to yours, I found using google.
I simply can't understand why people thing "Cmd-Shift-4" is a valid
reply to a question asked in a *scripting* mailing list.
But here is the script I've done, so that anyone might have a use from it.
It's using "SWF & FLV Player" to step through all the frames of a flash
animation, taking screenshots of all of the frames.
One question in regards to that: I saved it as a program bundle and
always recveive an error when it finishes because it cant write back the
changed properties. If anyone has an idea how to solve that, please tell
me...
--
-- Captain Shlomo 2008 by Skeeve
-- captain dot shlomo dot skeeve at xoxy dot net
--
-- a program to take snapshots of frames of an
-- swf/flv animation
--
-- Why "Captain Shlomo"?
-- "captain" (abbr. cpt.) is a pun of "capture"
-- "shlomo" is a pun (maybe just german) of Slo Mo
-- for Slow Motion.
--
-- Be aware that each frame needs about 4 seconds on a
-- 1,67GHz PPC
-- So taking a 24fps 5 minute animation is an 8 hour job
--
-- start frame
property sframe : 3
-- end frame
property eframe : 3757
-- bordersizes of playerwidow
property pwin : {north:54, east:5, south:5, west:5}
-- screen resolution
property scrn : {1440, 960}
-- where to save the temporary snapshot (a bit unclean this...)
property tmp_image : "/tmp/cpt.png"
-- where to find sips
property SIPS : "/usr/bin/sips"
-- where to find screencapture
property SCREENCAPTURE : "/usr/sbin/screencapture"
-- default save location
property last_folder : path to "cusr"
on run
tell application "System Events"
tell application process "SWF & FLV Player"
-- get the player window
set pref to a reference to (first UI element whose name is
it's title)
try
set windowtitle to title of pref
on error
display alert "Couldn't find a «SWF & FLV Player»
window" message "Start «SWF & FLV Player» with an swf/flv file but don't
start playing it." as critical
return
end try
end tell
end tell
-- where to store the output
set last_folder to choose folder with prompt "Choose the folder
where to store the images" default location last_folder
-- which frames
set sframe to the text returned of (display dialog "First Frame"
default answer sframe) as number
set eframe to the text returned of (display dialog "Last Frame"
default answer eframe) as number
-- activate the player
tell application "SWF & FLV Player"
activate
end tell
tell application "System Events"
tell application process "SWF & FLV Player"
-- get it's size
-- preferably you've set the original size before
set psiz to size of pref
-- calculate content size
set csiz to {(first item of psiz) - (west of pwin) - (east
of pwin), (second item of psiz) - (north of pwin) - (south of pwin)}
-- calculate the center of the screen
set origin to {((first item of scrn) - (west of pwin) +
(east of pwin) - (first item of psiz)) div 2, ((second item of scrn) -
(north of pwin) + (south of pwin) - (second item of psiz)) div 2}
-- and center the player window
set position of pref to origin
end tell
end tell
-- precalculate the command
set snapcommand to (quoted form of SCREENCAPTURE) & " -x " & (quoted
form of tmp_image) & " && " & (quoted form of SIPS) & " -c " & (second
item of csiz) & " " & (first item of csiz) & " " & (quoted form of
tmp_image) & " --out " & (quoted form of POSIX path of last_folder)
-- precalculate the filenamepattern
set fnp to text 1 thru (length of (eframe as string)) of "0000000000"
tell application "System Events"
tell application process "SWF & FLV Player"
-- now make a snapshot of each frame
repeat with cframe from sframe to eframe
set cf to cframe as string
-- go to frame...
keystroke "g" using command down
-- ...number cframe (cvf is it as a string)
keystroke cf
set clicked to false
-- check all windows
repeat with w in (every UI element whose subrole is
"AXDialog")
try
-- if it is our "go to frame" window
if value of first text field of w is cf then
-- click it's ok button
click button "OK" of w
set clicked to true
exit repeat
end if
end try
end repeat
-- success or not?
if not clicked then
display alert "Giving up" message "Couldn't find
Go-To-Frame window."
return
end if
-- now run the command
do shell script snapcommand & my leftfill(cframe, fnp) &
".png"
end repeat
end tell
end tell
end run
to leftfill(a_number, a_pattern)
set a_number to a_number as string
set missing to (length of a_pattern) - (length of a_number)
if missing < 1 then return a_number
return (text 1 thru missing of a_pattern) & a_number
end leftfill
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden