Can anyone think of a way to crop the rendered image based on the alpha of that frame?
I am creating a series of 2d images for a flash game. I have setup each image on it’s own frame, so when I export the first 25 frames of my animation, I then get 25 images that I use in flash. This has worked well, but each image stays the size of the frame (as you would expect and want when creating a animation). If I could have the images auto cropped by blender it would reduce my file sizes and solve some technical problems I am having with using large images in flash.
Thanks for your post secundar, but I don’t see how that is suppose to work. I have tried it and all I end up with is my original image with a white background, not cropped to the desired size.
In the Compositor, wire up your image [sequence] to the bottom of an AlphaOver node. In the top imput of the AlphaOver wire up a RenderLayer consisting of black at the size of the desired crop (I changed the sky to black.)
From what I can tell, the “AlphaOver” node only combines two images, it doesn’t effect the size of the frame that is saved. You have done this before, so I must not be doing something right, but I don’t know what that could be. Here is what I have done:
Original image (in this case a green button) is connected to the bottom input of an AlphaOver node
To create a black box to tell the compositor where to crop, I wire the alpha of my image to an “RGB Curves” node, invert the curve so the object is black and around it is white
I then wire this edited black and white image into the top of the AlphaOver node.
The output from the AlphaOver node goes into my Composite node at the “Image” input
Thanks for your suggestion secundar, but what you show does not change the dimensions of the rendered image. The Viewer node does not show the image that gets saved, to show that you need to use the Composite node.
If the frame is set to be for instance SizeX: 200, SizeY: 600
You scale your Render Layer node to 100x100
Combine the Render Layer and the image on an AlphaOver node
Send that output to the Composite node and then render
The image that gets saved is still 200x600, not 100x100, and even if the scale technique did crop the image to that size, it does not do it based on the color in a supplied image.
Attached is the setup I described as well as the output image.
Unless someone can show me otherwise, I believe this is not yet possible, to have the effect of a crop render node, but it is being worked on:
Blender saves the image in the resolutions specified in the Format panel. The nodes crop the image to the top socket from the middle of the supplied image out. So a output format image of 200x600, when a 100x100 image is fed to a top socket, will result in an image with a center of 100x100 and a black border around it. Hence the need for the scale node.
I have figured out what I was doing differently from you, secundar, why when I tried using the crop node it did not produce the same effects you were achieving.
I had the “Do Composite” button depressed.
The output is not based on the alpha of an image, like I originally wanted, but with this I now know how to precisely crop an image with a specific x and y value. If only I could make those x and y values dependent upon the alpha of an image, I would be all set.
Thanks for responding, contrast. I was puzzled as to why it wouldn’t work for you.
As for your new challenge, perhaps using a Separate RGBA - to pipe the Alpha into the Alpha Over node would do the trick. Let me know how it goes and, if you cannot figure it out, post up the image with alpha you’re trying to crop.
I don’t know of any program that will crop your output based on the alpha dimensions. The only program that I’ve seen that does anything close to this is After Effects which will import vector art as compositions whose layers are cropped to max x, y - dimensions of the line art. Probably the best you ccan hope for at this point is to “Trace Bitmap” (color threshold of 10 generally produces descent results), then delete the alpha.
I’ve wished for this same feature too. It just makes sense when it comes to sprites.