Flatten / expand clipping group, crop each object in it to the clipping path
It would be great to be able to convert a clipping mask into a crop.
Adobe will never invent any development of once teleased tools. It's such a bugy and inconsitent UI and this feature lacks for years ...
Yet another solution we can try to workaround this.
Jussi Jokinen commented
For anyone interested: I made a js solution to this problem for my own pen plotting / laser cutting purposes. https://github.com/jokjus/SVGFlattener
No guarantees of anything :) It's meant for simple shapes and paths and it definitely won't keep complex fills. But if you just want to flatten the clipping masks of an image and keep the shape outlines, it'll do the trick.
Indeed, the link got broken. Perhaps Dropbox made some changes.
Please try this one. Also share some feedback after you use the script.
Sergei Berman commented
Can you re-upload the script? Link does not work
OK, UV does not allow scripts, so here’s the link:
Hey, Mark and others.
I asked Sergey Osokin (https://github.com/creold/illustrator-scripts/) for help and after some fiddling with the script written by Carlos Canto we now have the script that does crop the image to the clipping mask — which is something I always wanted, so I’m pretty happy.
The mask stays, the clip group stays, but the image is now cropped to have only pixels that fit into the mask’s bounding box.
The size of this image is obviously going to be slightly larger than bounding box (you can't cut a pixel). Sometimes you get an extra row/column, but you got to be lucky.
Position stays (oh, it took us some time to workaround).
If you crop an RGB image in CMYK workspace, it’d become CMYK — obviously, because it gets embedded if it was linked.
Please try it out and share your feedback here.(Edited by admin)
Oscar, yeah, I am seeing the problem and confirm it.
If you want more automated solution, you can try https://mai-tools.com/super-magic-eraser commercial script. Hope this can help at least in some cases.
Oscar Obians commented
Hi Egor, It's been a while since I posted the comment above but if I remember correctly, I had issues expanding some complex repeat objects. I covered it in this video: https://youtu.be/n1_p_qCGdlo?t=468
Jan, can you illustrate it with a mockup?
What do you have, and what you expect to get?
Oscar, you can Expand new Repeat objects, and it gives a clipping group. What do you expect to get then? Please elaborate.
Mark R commented
This would be super useful and save a bunch of time. Currently when you click 'Crop Image' the crop location is pretty random. Most of the time I don't want to crop an image until I check it out with a clipping mask first. In fact most of the I don't think it's a good workflow to be committing to cropping an image before at least looking at it as a clipping mask. But once you've put the work into making a clipping mask you shouldn't have to make the rectangle again. Either or both, the 'Crop Image' button should default to the shape of the clipping mask, and/or a 'Crop Image to Clipping Mask...' option should be added to as an Image right click drop-down menu to when it already has a clipping mask.
If an image already has a clipping mask having to click and drag after clicking 'Crop Image' is just non-intuitive. It should already be in the boundary of the clipping mask as default.
Jan, this is an extremely difficult task.
Remember, we can clip whatever we want. Gradient mesh grids, art with opacity masks, linked images, live text — how do you see the operation handling all of these?
Jan Vork commented
A clipping mask is a non destructive Pathfinder function avant la lettre.
Please make it possible to 'expand' it, in the same way as Compound Pathfinder shapes.
I've wanted a simple "crop everything below" feature for 13 years...
The only way to crop multiple objects at the same time (without destroying shapes and messing up gradients within the crop) is to use the "Divide objects below" which cuts through everything below like a cookie cutter. But then you have to delete everything outside your crop shape manually afterwards which can take really long time if you're working with complex shapes and a tons of objects.
"Divide objects below" also screws up gradients completely (by applying the gradients to the new shapes created) so it only works with solid fills. And it doesn't cut stroked open paths either so they have to be expanded first.
Oscar Obians commented
Because of the absence of this feature, there is no easy way to Expand the new Repeat tools that were introduced with the 25.1 update
That is because there is no such a thing as Apply Clipping Mask :)
You can clip art that is far away from being able to be cropped: meshes, linked images, live brushes, text... Crop is a destructive thing. Crop removes all live strokes form the objects within the mask and messes with order of objects. It’s NOT a Flatten Clip Path and is no meant to do it, it’s a basic boolean operation that occasionally works as it can substitute Apply Clipping Path absent command.
Unfortunately, there is no one, I wish we had though.
But there are script that try to substitute it, like Super Magic Eraser: https://mai-tools.com/super-magic-eraser
Clayton Shima commented
Now, to do the same with vectors, I guess that development would have to deal with so many problems, it may not even be worth the time. On top of that, I would rather not have noob designers use such a feature, as it would make the work of doing modifications to art a near impossible thing. Let the beginner illustrators keep all the artwork intact but just masked. We veterans appreciate.
Clayton Shima commented
For raster images, you can already do this within Illustrator.
1-Copy the vectors of the mask (JUST the vector, not the image contained inside!)
2-Deselect all and click to selected the mask + masked image set
3-Set the mixing option in the Transparency palette to Multiply
4-Paste the mask vector in back (Ctrl + B) and paint it white
5-Shift+click to selected also the mask + masked image set again.
6-Group (Shift + G)
7-From the Object menu, select "Flatten transparency", setting quality adequately
(This may create segmented images, which you may optionally just rasterize again as a whole single image.)
This will create a standalone raster image in the size of the mask. However, this process is not perfect, and if you need precise pixels around the borders of the image, you might still need a mask to create crisp edges.