When ImageEvents don’t suffice, I tend to use PHP for image manipulation.
Scenario: a folder with hundreds of image-sequences, all having unwanted borders of the same width.
My solution:
(*
expects a folder containing image sequence of jpegs
Cuts off pixels from the borders and replaces the original files
should you be cropping more than there is available
in any direction then that image remains untouched
requires PHP 5 or at least gd.lib installed
written 20070809 by Luke JZ aka SwissalpS http://bbs.applescript.net/profile.php?id=15718
Creative Commons Non Comercial Share Alike
*)
-- set these for your needs
-- iLeft, iTop, iRight, iBottom represent the amount of pixels you would like to remove
-- iQuality is a value from 0 to 100 where 0 makes the smallest files
set {iLeft, iTop, iRight, iBottom, iQuality, fileList, phpPath} to {50, 50, 30, 70, 100, makeFileList(choose folder), "/usr/local/php5/bin/php"}
-- the rest of this script doesn't need any changing
set phpScript to "$aFiles = array(" & filesListPHPready(fileList) & ");
foreach($aFiles as $sPathFile) {
fCropAwayBorders($sPathFile, " & iLeft & ", " & iTop & ", " & iRight & ", " & iBottom & ", " & iQuality & ");
}
function fCropAwayBorders($sPathFile, $iLeft, $iTop, $iRight, $iBottom, $iQuality = 75) {
if ((0 > $iQuality) || (100 < $iQuality)) { $iQuality = 75; }
$rImgO = @imagecreatefromjpeg($sPathFile); // Attempt to open
if (! $rImgO) { // See if it failed
$rImgN = imagecreatetruecolor(384, 248); // Create a black image
$iBackCol = imagecolorallocate($rImgN, 0, 0, 0);
$iTextCol = imagecolorallocate($rImgN, 255, 255, 255);
imagefilledrectangle($rImgN, 0, 0, 384, 248, $iBackCol);
// Output an errmsg
imagestring($rImgN, 1, 5, 5, 'Error loading ' . $sPathFile, $iTextCol);
} else {
$aSize = getimagesize($sPathFile);
$iDestX = 0; $iDestY = 0; $iSrcX = $iLeft; $iSrcY = $iTop;
$iSrcW = $aSize[0] - $iLeft - $iRight;
$iSrcH = $aSize[1] - $iTop - $iBottom;
$rImgN = imagecreatetruecolor($iSrcW, $iSrcH);
imagecopy($rImgN, $rImgO, $iDestX, $iDestY, $iSrcX, $iSrcY, $iSrcW, $iSrcH);
}
$bSaveCheck = @imagejpeg($rImgN, $sPathFile, $iQuality);
}"
set shellScript to phpPath & " -r " & quoted form of phpScript
set theResult to do shell script shellScript
to filesListPHPready(fileList)
set fileString to ""
repeat with thisItem in fileList
if "" ≠fileString then
set fileString to fileString & ", '" & (POSIX path of thisItem) & "'"
else
set fileString to fileString & "'" & (POSIX path of thisItem) & "'"
end if
end repeat
return fileString
end filesListPHPready
to makeFileList(startFolder)
tell application "Finder"
set fileList to startFolder's files
set outList to {}
repeat with thisItem in fileList
set outList's end to thisItem as alias
end repeat
end tell
return outList
end makeFileList