“How do I crop a Photo in Illustrator?” is the All-Time hottest topic in the Adobe Illustrator Forum, there’s a long thread with answers that go from “not possible”, to “use Photoshop”, to “use clipping masks”, to “use Artboards”. The thread also has the real answer to the question, cropping raster images in Illustrator is possible using a “cutter” path with a blending mode other than Normal, then Flattening Transparency. Great answer!! now this script tackles on the same principle as Flattening Transparency, it rasterizes the image within the bounds of the “cutter” path and discards what’s outside of the path bounds.
to use the script to Crop this image
draw a rectangle on top of the image to use as “cutter” path
select both, the image and the “cutter” path
run the imageCrop script
that’s all, the image gets cropped, embedded, unwanted pixels get discarded. If you don’t want your images to get destroyed, please use the other Masking methods.
Press Shift Key before running the script to Rasterize using TypeOptimized option otherwise the script will use default ArtOptimized
Press Alt Key before running the script to Rasterize using custom Resolution, otherwise the script will use an average of the base image resolution.
Scripting Adobe Illustrator is painful at times, we don’t have access to some of the most useful features available to us manually using the UI, and we also don’t have the luxury of major upgrades to the DOM as ID or PS users have enjoyed for years. With the release of CS6 some years back, Adobe surprised us with a couple of new, although undocumented commands that seemed to have great potential. One of them was executeMenuCommand(menuCommandString), the string syntax was missing, but fortunately it was quickly found out by some talented scripters, proving its value, and becoming one of the most, if not the most powerful command available.
The other command released with CS6 was applyEffect(liveEffectXML), which also had its string syntax missing, till now…well, without further ado, here’s an example
the important part of the string is the data, mlim is the MiterLimit Value “4”, ofst is the Offset Value “20”, jntp is the Join Type “2” for Miter.
How to get the XML string parameter
To get the right xml string for a particular Effect, fire up Illustrator CS5 or CS6, draw a rectangle, apply a Live Offset Path as show above, then save your file as FXG
Make sure “Save Illustrator Private Data” is selected, then click on “Show Code…”, you’ll get the xfg text file generated.
Look for the LiveEffect tag and get the name and the Dict data from it as shown below
<LiveEffect name=”Adobe Offset Path”><Dict data=”R mlim 4 R ofst 20 I jntp 2 “/></LiveEffect>
that’s all, that’s the xml string you need to add to your script.
I would like to thank Adobe’s Sanjay Kumar, without his input this command would have not seen the light of day.