Last active
September 15, 2021 06:56
-
-
Save Inventsable/8914a86153a6fad831904bb69199621c to your computer and use it in GitHub Desktop.
Simple way to scramble all text inside an Illustrator document
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Scramble all text within an Illustrator document | |
* https://gist.github.com/Inventsable/8914a86153a6fad831904bb69199621c | |
* | |
* Uses a very simple method to randomize each letter, not something like Ipsum text. | |
* If not using a monospace font, can cause overflow or change of dimensions. | |
* | |
* Example: "Lorem ipsum" becomes "gtnuq muwne" | |
*/ | |
Array.prototype.forEach = function (callback) { | |
for (var i = 0; i < this.length; i++) callback(this[i], i, this); | |
}; | |
function randomBetween(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
}; | |
function get(type, parent, deep) { | |
if (arguments.length == 1 || !parent) { | |
parent = app.activeDocument; | |
deep = false; | |
}; | |
var result = []; | |
if (!parent[type]) return []; | |
for (var i = 0; i < parent[type].length; i++) { | |
result.push(parent[type][i]); | |
if (parent[type][i][type] && deep) | |
result = [].concat(result, get(type, parent[type][i])); | |
}; | |
return result || []; | |
}; | |
function scrambleText(string) { | |
var result = "", | |
alphabet = "abcdefghijklmnopqrstuvwxyz"; | |
for (var i = 0; i < string.length; i++) | |
result += /[a-zA-Z]/i.test(string[i]) | |
? alphabet[randomBetween(0, 25)] | |
: string[i] | |
return result; | |
}; | |
get("textFrames") | |
.forEach(function (item) { | |
item.contents = scrambleText(item.contents); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment