javascript - How to decode base64 encoded image with JS/PHP? (previously encoded with Actionscript) -
i have image encoded base64, made actionscript function:
private static const base64_chars:string = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/="; public static function encodebytearray(_arg1:bytearray):string { var _local3:array; var _local5:uint; var _local6:uint; var _local7:uint; var _local2 = ""; var _local4:array = new array(4); _arg1.position = 0; while (_arg1.bytesavailable > 0) { _local3 = new array(); _local5 = 0; while ((((_local5 < 3)) && ((_arg1.bytesavailable > 0)))) { _local3[_local5] = _arg1.readunsignedbyte(); _local5++; }; _local4[0] = ((_local3[0] & 252) >> 2); _local4[1] = (((_local3[0] & 3) << 4) | (_local3[1] >> 4)); _local4[2] = (((_local3[1] & 15) << 2) | (_local3[2] >> 6)); _local4[3] = (_local3[2] & 63); _local6 = _local3.length; while (_local6 < 3) { _local4[(_local6 + 1)] = 64; _local6++; }; _local7 = 0; while (_local7 < _local4.length) { _local2 = (_local2 + base64_chars.charat(_local4[_local7])); _local7++; }; }; return (_local2); }
now i'm trying decode (with no success) string in js/php , have image. here actionscript decoding function:
public static function decodetobytearray(_arg1:string):bytearray{ var _local6:uint; var _local7:uint; var _local2:bytearray = new bytearray(); var _local3:array = new array(4); var _local4:array = new array(3); var _local5:uint; while (_local5 < _arg1.length) { _local6 = 0; while ((((_local6 < 4)) && (((_local5 + _local6) < _arg1.length)))) { _local3[_local6] = base64_chars.indexof(_arg1.charat((_local5 + _local6))); _local6++; }; _local4[0] = ((_local3[0] << 2) + ((_local3[1] & 48) >> 4)); _local4[1] = (((_local3[1] & 15) << 4) + ((_local3[2] & 60) >> 2)); _local4[2] = (((_local3[2] & 3) << 6) + _local3[3]); _local7 = 0; while (_local7 < _local4.length) { if (_local3[(_local7 + 1)] == 64){ break; }; _local2.writebyte(_local4[_local7]); _local7++; }; _local5 = (_local5 + 4); }; _local2.position = 0; return (_local2); }
i tried convert decoding aactionscript function js i'm missing new bytearray();
don't know how manage that. need way decode encoded image string image. here sample base64 string of image, encoded "encodebytearray" function:
thanks help.
to output base64 image use format:
<img src="data:image/png;base64,abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/=" />
Comments
Post a Comment