Ported from php to node //TODO: image up