The ASObjC Runner wouldn’t compile after the first run for me. I can’t remember what I did exactly, but probably: repair disk permissions, cold start, zap the PRAM, and I might have made it 64 bit I think in the info window. Oh, and try quitting it in the status menu.
Edited: if you don’t have the menu icon, then:
tell app “ASObjC Runner” to quit
Restarted everything and the script is running fine.
Just having issues with the height and width settings. Are they percentages do you know?
Been experimenting with them but can’t seem to come up with any pattern to how they work.
I assume one set of them is the final image size and the second the position it crops from?
It’s not, though. It’s actually a struct, which is C thing that you can use a bit like a dictionary or record, but really just packs all the bits together in a structured way. There’s no direct AS equivalent because, apart from anything else, AS doesn’t support primitive data types – everything in AS is really an object.
Anyway, ASObjC gets around this by automatically converting between a handful of structs and AS records. So an NSRect is returned as:
The origin value is another struct, NSPoint, and the size is also a struct: NSSize.
The other one you’ll strike often in ASObjC is NSRange, which is how ranges of text are typically described: {|location|:theLocation, |length|:theLength} . The location is the zero-based offset of a string, and the length is the number of characters in the range.
Interesting. The script works perfectly but returns an error: unrecognized function size (-10000)
when I move it to an identical machine running the same ASObjC Runner and OSX version.
Tried just changing a few size numbers but the error persists.
For completeness. I’ve fixed the errors in the first part of Carl’s original script so that it works for me. There were numerous errors but your initial problem was that the path needs to be made into a file or alias object for iMagine Photo to know what to do with it. See script below.
In terms of performance I’d think that this would give Shane’s excellent solution a run for its money.
I wouldn’t however recommend using iMagine Photo as I haven’t updated it since 2006 and it is not going to be updated.
Kevin
set thisFile to "MacintoshHD:Users:ktam:Phone Pictures:07-08-2011 17.18.35.jpg" as alias
set exportFile to "MacintoshHD:Users:ktam:Desktop:cropped.jpg"
tell application "iMagine Photo"
set thisImporter to import graphic thisFile
set {x, y, xDim, yDim} to source rectangle of thisImporter
tell thisImporter to make exporter
set the export file location of thisImporter to file exportFile
set theTop to (yDim / 4) as integer
set theLeft to (xDim / 4) as integer
set theRight to ((xDim / 2) + theLeft) as integer
set theBottom to ((yDim / 2) + theTop) as integer
set the source rectangle of thisImporter to {theLeft, theTop, theRight, theBottom}
export thisImporter
close thisImporter
end tell
I’ve been doing other things for the last 10 years. Though I did do some updates to iMagine Photo for the first few years. I am however working for myself again so I’m onto a new project.
I know that iMagine Photo will run in the next version of OS X but I hadn’t expected it to.
I don’t see any point in updating iMagine Photo now as it depends on the carbon API of Quicktime which is 32 bit bound and I can’t see it surviving post Mavericks.
I am now working on a replacement for iMagine Photo but it won’t be applescript, but instead a mixture of unix shell scripts and json. I will have an alpha version released late October early November. It will be missing a lot of the final functionality I have planned but will have a lot of useful functionality. I am expecting to finish coding for the first alpha version release within a couple of weeks and I’ll then be onto writing the documentation.
In some ways the new tool is similar to iMagine Photo. It is running as a LaunchAgent (a user process daemon). iMagine Photo can be run as a UIElement faceless application. Like iMagine Photo the LaunchAgent stays alive between each message it receives as long as it is maintaining state (there are still objects alive that can be referenced) and maintains an idle time which keeps the tool alive for a specified period after all state is destroyed.
The new tool will be free. It will only run on Mavericks or later.
When I do the alpha release I’ll be looking for testers.
Cropping should have very little effect on the image quality, but if you’re starting with a PDF and going to any sort of bitmap, type will have to suffer. You could increase the DPI, but although that would help with the type, it would probably do awful things with any pictures – if you’re getting 72dpi, it’s because the original is probably 72dpi.
I’m not sure I follow. When you crop an image, you always end up with fewer pixels – that’s more or less the definition of cropping while maintaining the same resolution.
What cropping are you trying to apply to the image?