Skip to content

Instantly share code, notes, and snippets.

@daveWid
Created January 20, 2011 23:09
Show Gist options
  • Save daveWid/788895 to your computer and use it in GitHub Desktop.
Save daveWid/788895 to your computer and use it in GitHub Desktop.
Remove Transparency from Illustrator Files
/**
* Run through all of the paths and turn the transparency to
* 100% to avoid problems in flash.
*/
var Transparency = {
total: 0,
// Removes all of the transparency
remove:function(){
this.total = 0; // Resetting
var layers = app.activeDocument.layers;
this.forEach(layers, this.runLayer);
app.redraw();
alert(this.total + " paths updated");
},
/**
* Loops through the object running the func on each object in an array.
*
* @param obj Array to iterate over
* @param func The function to call
*/
forEach:function(obj, func){
var len = obj.length;
for (var i = 0; i < len; i++){
func.call(Transparency, obj[i]);
}
},
/**
* Runs through the layer, getting the paths and groups
*
* @param layer The layer to operate on
*/
runLayer:function(layer){
var fe = this.forEach;
fe(layer.pathItems, this.setOpacity);
fe(layer.groupItems, this.setOpacity); // Need to set the opacity on the group as well
fe(layer.groupItems, this.runGroup);
fe(layer.layers, this.runLayer);
},
/**
* Sets the opacity of the object
*
* @param obj Object to set the opacity of
*/
setOpacity:function(obj){
if (obj.opacity < 100){
obj.opacity = 100;
this.total++;
}
},
/**
* Runs the opacity on the groups
*
* @param groups GroupsItems object
*/
runGroup:function(group){
var fe = this.forEach;
fe(group.pathItems, this.setOpacity);
fe(group.groupItems, this.setOpacity); // Need to set the opacity on the group as well
fe(group.groupItems, this.runGroup);
}
};
// And get a move on
Transparency.remove();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment