Well there is -- I was just trying to keep it simple.
So what you need to do is create a new bitmapImageRep, using possibly the longest method in the Cocoa frameworks, fill it with white, then draw to it from the original bitmapImageRep. Doing this, you also control what portion gets drawn and drawn to -- so you can crop and scale. You also control how the images are composited together.
The drawing part involves what's known as the graphics context. You save its existing state, set it to a new context with the new bitmapImageRep as target, do the filling and drawing, then restore the saved context. If it sounds complex, that's only because it is. So:
use scripting additions
use framework "Foundation"
use framework "AppKit"
set thePath to "/Users/shane/Desktop/Testing.bmp"
its fileFromClipToPath:thePath
on fileFromClipToPath:thePath
set pb to current application's NSPasteboard's generalPasteboard() -- get pasteboard
set theType to pb's availableTypeFromArray:{current application's NSPasteboardTypeTIFF}
if the theType is missing value then error "No suitable image data found on the clipboard"
-- log theType as text
set theData to pb's dataForType:theType
set oldRep to current application's NSBitmapImageRep's imageRepWithData:theData
-- get size of bitmap
set {width:theWidth, height:theHeight} to oldRep's |size|()
-- calculate new height
set newHeight to theHeight - 50 -- whatever you want to chop off
-- make new bitmapImageRep
set newRep to (current application's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:theWidth pixelsHigh:newHeight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(current application's NSCalibratedRGBColorSpace) bitmapFormat:(current application's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
-- store the existing graphics context
current application's NSGraphicsContext's saveGraphicsState()
-- set graphics context to new context based on the new bitmapImageRep
(current application's NSGraphicsContext's setCurrentContext:(current application's NSGraphicsContext's graphicsContextWithBitmapImageRep:newRep))
-- set the color to white
current application's NSColor's whiteColor()'s |set|()
-- fill the bitmapImageRep with white
current application's NSRectFill({origin:{x:0, y:0}, |size|:{width:theWidth, height:theHeight}})
-- draw from the original bitmapImageRep to the new one
oldRep's drawInRect:{origin:{x:0, y:0}, |size|:{width:theWidth, height:newHeight}} fromRect:{origin:{x:0, y:0}, |size|:{width:theWidth, height:newHeight}} operation:(current application's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
-- restore graphics state
current application's NSGraphicsContext's restoreGraphicsState()
-- save bitmapImageRep as image
set theData to (newRep's representationUsingType:(current application's NSBMPFileType) |properties|:{NSImageProgressive:false})
set theResult to (theData's writeToFile:thePath atomically:true)
return (theResult = 1)
end fileFromClipToPath:
You can also do rotation similarly, using affine transforms. That gets a bit more complicated.