Last active
September 5, 2019 20:40
-
-
Save Sanix-Darker/605d35224c727494c55f52462005beb5 to your computer and use it in GitHub Desktop.
[PHP]Writing text on Animated GIF PHP
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
Class PANDA_decode { | |
var $PANDA_TR = - 1; | |
var $PANDA_TG = - 1; | |
var $PANDA_TB = - 1; | |
var $PANDA_TI = 0; | |
var $PANDA_buffer = Array(); | |
var $PANDA_arrays = Array(); | |
var $PANDA_delays = Array(); | |
var $PANDA_dispos = Array(); | |
var $PANDA_stream = ""; | |
var $PANDA_string = ""; | |
var $PANDA_bfseek = 0; | |
var $PANDA_anloop = 0; | |
var $PANDA_screen = Array(); | |
var $PANDA_global = Array(); | |
var $PANDA_sorted; | |
var $PANDA_colorS; | |
var $PANDA_colorC; | |
var $PANDA_colorF; | |
function __construct($PANDA_pointer) | |
{ | |
$this->PANDA_stream = $PANDA_pointer; | |
PANDA_decode::PANDA_get(6); | |
PANDA_decode::PANDA_get(7); | |
$this->PANDA_screen = $this->PANDA_buffer; | |
$this->PANDA_colorF = $this->PANDA_buffer[4] & 0x80 ? 1 : 0; | |
$this->PANDA_sorted = $this->PANDA_buffer[4] & 0x08 ? 1 : 0; | |
$this->PANDA_colorC = $this->PANDA_buffer[4] & 0x07; | |
$this->PANDA_colorS = 2 << $this->PANDA_colorC; | |
if ($this->PANDA_colorF == 1) | |
{ | |
PANDA_decode::PANDA_get(3 * $this->PANDA_colorS); | |
$this->PANDA_global = $this->PANDA_buffer; | |
} | |
for ($cycle = 1; $cycle;) | |
{ | |
if (PANDA_decode::PANDA_get(1)) | |
{ | |
switch ($this->PANDA_buffer[0]) | |
{ | |
case 0x21: | |
PANDA_decode::PANDAReadX(); | |
break; | |
case 0x2C: | |
PANDA_decode::PANDA_Y(); | |
break; | |
case 0x3B: | |
$cycle = 0; | |
break; | |
} | |
} | |
else | |
{ | |
$cycle = 0; | |
} | |
} | |
} | |
function PANDAReadX() | |
{ | |
PANDA_decode::PANDA_get(1); | |
if ($this->PANDA_buffer[0] == 0xff) | |
{ | |
for (;;) | |
{ | |
PANDA_decode::PANDA_get(1); | |
if (($u = $this->PANDA_buffer[0]) == 0x00) | |
{ | |
break; | |
} | |
PANDA_decode::PANDA_get($u); | |
if ($u == 0x03) | |
{ | |
$this->PANDA_anloop = ($this->PANDA_buffer[1] | $this->PANDA_buffer[2] << 8); | |
} | |
} | |
} | |
else | |
{ | |
for (;;) | |
{ | |
PANDA_decode::PANDA_get(1); | |
if (($u = $this->PANDA_buffer[0]) == 0x00) | |
{ | |
break; | |
} | |
PANDA_decode::PANDA_get($u); | |
if ($u == 0x04) | |
{ | |
if ($this->PANDA_buffer[3] & 0x80) | |
{ | |
$this->PANDA_dispos[] = ($this->PANDA_buffer[0] >> 2) - 1; | |
} | |
else | |
{ | |
$this->PANDA_dispos[] = ($this->PANDA_buffer[0] >> 2) - 0; | |
} | |
$this->PANDA_delays[] = ($this->PANDA_buffer[1] | $this->PANDA_buffer[2] << 8); | |
if ($this->PANDA_buffer[3]) | |
{ | |
$this->PANDA_TI = $this->PANDA_buffer[3]; | |
} | |
} | |
} | |
} | |
} | |
function PANDA_Y() | |
{ | |
$PANDA_screen = Array(); | |
PANDA_decode::PANDA_get(9); | |
$PANDA_screen = $this->PANDA_buffer; | |
$PANDA_colorF = $this->PANDA_buffer[8] & 0x80 ? 1 : 0; | |
if ($PANDA_colorF) | |
{ | |
$PANDA_code = $this->PANDA_buffer[8] & 0x07; | |
$PANDA_sort = $this->PANDA_buffer[8] & 0x20 ? 1 : 0; | |
} | |
else | |
{ | |
$PANDA_code = $this->PANDA_colorC; | |
$PANDA_sort = $this->PANDA_sorted; | |
} | |
$PANDA_size = 2 << $PANDA_code; | |
$this->PANDA_screen[4]&= 0x70; | |
$this->PANDA_screen[4]|= 0x80; | |
$this->PANDA_screen[4]|= $PANDA_code; | |
if ($PANDA_sort) | |
{ | |
$this->PANDA_screen[4]|= 0x08; | |
} | |
if ($this->PANDA_TI) | |
{ | |
$this->PANDA_string = "GIF89a"; | |
} | |
else | |
{ | |
$this->PANDA_string = "GIF87a"; | |
} | |
PANDA_decode::PANDA_add($this->PANDA_screen); | |
if ($PANDA_colorF == 1) | |
{ | |
PANDA_decode::PANDA_get(3 * $PANDA_size); | |
if ($this->PANDA_TI) | |
{ | |
$this->PANDA_TR = $this->PANDA_buffer[3 * $this->PANDA_TI + 0]; | |
$this->PANDA_TG = $this->PANDA_buffer[3 * $this->PANDA_TI + 1]; | |
$this->PANDA_TB = $this->PANDA_buffer[3 * $this->PANDA_TI + 2]; | |
} | |
PANDA_decode::PANDA_add($this->PANDA_buffer); | |
} | |
else | |
{ | |
if ($this->PANDA_TI) | |
{ | |
$this->PANDA_TR = $this->PANDA_global[3 * $this->PANDA_TI + 0]; | |
$this->PANDA_TG = $this->PANDA_global[3 * $this->PANDA_TI + 1]; | |
$this->PANDA_TB = $this->PANDA_global[3 * $this->PANDA_TI + 2]; | |
} | |
PANDA_decode::PANDA_add($this->PANDA_global); | |
} | |
if ($this->PANDA_TI) | |
{ | |
$this->PANDA_string.= "!\xF9\x04\x1\x0\x0" . chr($this->PANDA_TI) . "\x0"; | |
} | |
$this->PANDA_string.= chr(0x2C); | |
$PANDA_screen[8]&= 0x40; | |
PANDA_decode::PANDA_add($PANDA_screen); | |
PANDA_decode::PANDA_get(1); | |
PANDA_decode::PANDA_add($this->PANDA_buffer); | |
for (;;) | |
{ | |
PANDA_decode::PANDA_get(1); | |
PANDA_decode::PANDA_add($this->PANDA_buffer); | |
if (($u = $this->PANDA_buffer[0]) == 0x00) | |
{ | |
break; | |
} | |
PANDA_decode::PANDA_get($u); | |
PANDA_decode::PANDA_add($this->PANDA_buffer); | |
} | |
$this->PANDA_string.= chr(0x3B); | |
$this->PANDA_arrays[] = $this->PANDA_string; | |
} | |
function PANDA_get($len) | |
{ | |
$this->PANDA_buffer = Array(); | |
for ($i = 0; $i < $len; $i++) | |
{ | |
if ($this->PANDA_bfseek > strlen($this->PANDA_stream)) | |
{ | |
return 0; | |
} | |
$this->PANDA_buffer[] = ord($this->PANDA_stream | |
{ | |
$this->PANDA_bfseek++}); | |
} | |
return 1; | |
} | |
function PANDA_add($bytes) | |
{ | |
foreach($bytes as $byte) | |
{ | |
$this->PANDA_string.= chr($byte); | |
} | |
} | |
function PANDA_frames() | |
{ | |
return ($this->PANDA_arrays); | |
} | |
function PANDA_delay() | |
{ | |
return ($this->PANDA_delays); | |
} | |
function PANDAGetLoop() | |
{ | |
return ($this->PANDA_anloop); | |
} | |
function PANDA_disposal() | |
{ | |
return ($this->PANDA_dispos); | |
} | |
function PANDA_T_R() | |
{ | |
return ($this->PANDA_TR); | |
} | |
function PANDA_T_G() | |
{ | |
return ($this->PANDA_TG); | |
} | |
function PANDA_T_B() | |
{ | |
return ($this->PANDA_TB); | |
} | |
} |
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
function upload_file($encoded_string, $target_dir, $frame_name_id){ | |
$decoded_file = base64_decode($encoded_string); // decode the file | |
$mime_type = finfo_buffer(finfo_open(), $decoded_file, FILEINFO_MIME_TYPE); // extract mime type | |
$extension = ImageController::mime2ext($mime_type); // extract extension from mime type | |
$file = uniqid() .'.'. $extension; // rename file as a unique name | |
$file_dir = $target_dir . $frame_name_id .'.'. $extension; | |
try { | |
file_put_contents($file_dir, $decoded_file); // save | |
// database_saving($file); | |
// header('Content-Type: application/json'); | |
// echo json_encode("File Uploaded Successfully"); | |
} catch (Exception $e) { | |
// header('Content-Type: application/json'); | |
// echo json_encode($e->getMessage()); | |
} | |
} | |
/* | |
to take mime type as a parameter and return the equivalent extension | |
*/ | |
function mime2ext($mime){ | |
$all_mimes = '{"png":["image\/png","image\/x-png"],"bmp":["image\/bmp","image\/x-bmp", | |
"image\/x-bitmap","image\/x-xbitmap","image\/x-win-bitmap","image\/x-windows-bmp", | |
"image\/ms-bmp","image\/x-ms-bmp","application\/bmp","application\/x-bmp", | |
"application\/x-win-bitmap"],"gif":["image\/gif"],"jpeg":["image\/jpeg", | |
"image\/pjpeg"],"xspf":["application\/xspf+xml"],"vlc":["application\/videolan"], | |
"wmv":["video\/x-ms-wmv","video\/x-ms-asf"],"au":["audio\/x-au"], | |
"ac3":["audio\/ac3"],"flac":["audio\/x-flac"],"ogg":["audio\/ogg", | |
"video\/ogg","application\/ogg"],"kmz":["application\/vnd.google-earth.kmz"], | |
"kml":["application\/vnd.google-earth.kml+xml"],"rtx":["text\/richtext"], | |
"rtf":["text\/rtf"],"jar":["application\/java-archive","application\/x-java-application", | |
"application\/x-jar"],"zip":["application\/x-zip","application\/zip", | |
"application\/x-zip-compressed","application\/s-compressed","multipart\/x-zip"], | |
"7zip":["application\/x-compressed"],"xml":["application\/xml","text\/xml"], | |
"svg":["image\/svg+xml"],"3g2":["video\/3gpp2"],"3gp":["video\/3gp","video\/3gpp"], | |
"mp4":["video\/mp4"],"m4a":["audio\/x-m4a"],"f4v":["video\/x-f4v"],"flv":["video\/x-flv"], | |
"webm":["video\/webm"],"aac":["audio\/x-acc"],"m4u":["application\/vnd.mpegurl"], | |
"pdf":["application\/pdf","application\/octet-stream"], | |
"pptx":["application\/vnd.openxmlformats-officedocument.presentationml.presentation"], | |
"ppt":["application\/powerpoint","application\/vnd.ms-powerpoint","application\/vnd.ms-office", | |
"application\/msword"],"docx":["application\/vnd.openxmlformats-officedocument.wordprocessingml.document"], | |
"xlsx":["application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application\/vnd.ms-excel"], | |
"xl":["application\/excel"],"xls":["application\/msexcel","application\/x-msexcel","application\/x-ms-excel", | |
"application\/x-excel","application\/x-dos_ms_excel","application\/xls","application\/x-xls"], | |
"xsl":["text\/xsl"],"mpeg":["video\/mpeg"],"mov":["video\/quicktime"],"avi":["video\/x-msvideo", | |
"video\/msvideo","video\/avi","application\/x-troff-msvideo"],"movie":["video\/x-sgi-movie"], | |
"log":["text\/x-log"],"txt":["text\/plain"],"css":["text\/css"],"html":["text\/html"], | |
"wav":["audio\/x-wav","audio\/wave","audio\/wav"],"xhtml":["application\/xhtml+xml"], | |
"tar":["application\/x-tar"],"tgz":["application\/x-gzip-compressed"],"psd":["application\/x-photoshop", | |
"image\/vnd.adobe.photoshop"],"exe":["application\/x-msdownload"],"js":["application\/x-javascript"], | |
"mp3":["audio\/mpeg","audio\/mpg","audio\/mpeg3","audio\/mp3"],"rar":["application\/x-rar","application\/rar", | |
"application\/x-rar-compressed"],"gzip":["application\/x-gzip"],"hqx":["application\/mac-binhex40", | |
"application\/mac-binhex","application\/x-binhex40","application\/x-mac-binhex40"], | |
"cpt":["application\/mac-compactpro"],"bin":["application\/macbinary","application\/mac-binary", | |
"application\/x-binary","application\/x-macbinary"],"oda":["application\/oda"], | |
"ai":["application\/postscript"],"smil":["application\/smil"],"mif":["application\/vnd.mif"], | |
"wbxml":["application\/wbxml"],"wmlc":["application\/wmlc"],"dcr":["application\/x-director"], | |
"dvi":["application\/x-dvi"],"gtar":["application\/x-gtar"],"php":["application\/x-httpd-php", | |
"application\/php","application\/x-php","text\/php","text\/x-php","application\/x-httpd-php-source"], | |
"swf":["application\/x-shockwave-flash"],"sit":["application\/x-stuffit"],"z":["application\/x-compress"], | |
"mid":["audio\/midi"],"aif":["audio\/x-aiff","audio\/aiff"],"ram":["audio\/x-pn-realaudio"], | |
"rpm":["audio\/x-pn-realaudio-plugin"],"ra":["audio\/x-realaudio"],"rv":["video\/vnd.rn-realvideo"], | |
"jp2":["image\/jp2","video\/mj2","image\/jpx","image\/jpm"],"tiff":["image\/tiff"], | |
"eml":["message\/rfc822"],"pem":["application\/x-x509-user-cert","application\/x-pem-file"], | |
"p10":["application\/x-pkcs10","application\/pkcs10"],"p12":["application\/x-pkcs12"], | |
"p7a":["application\/x-pkcs7-signature"],"p7c":["application\/pkcs7-mime","application\/x-pkcs7-mime"],"p7r":["application\/x-pkcs7-certreqresp"],"p7s":["application\/pkcs7-signature"],"crt":["application\/x-x509-ca-cert","application\/pkix-cert"],"crl":["application\/pkix-crl","application\/pkcs-crl"],"pgp":["application\/pgp"],"gpg":["application\/gpg-keys"],"rsa":["application\/x-pkcs7"],"ics":["text\/calendar"],"zsh":["text\/x-scriptzsh"],"cdr":["application\/cdr","application\/coreldraw","application\/x-cdr","application\/x-coreldraw","image\/cdr","image\/x-cdr","zz-application\/zz-winassoc-cdr"],"wma":["audio\/x-ms-wma"],"vcf":["text\/x-vcard"],"srt":["text\/srt"],"vtt":["text\/vtt"],"ico":["image\/x-icon","image\/x-ico","image\/vnd.microsoft.icon"],"csv":["text\/x-comma-separated-values","text\/comma-separated-values","application\/vnd.msexcel"],"json":["application\/json","text\/json"]}'; | |
$all_mimes = json_decode($all_mimes,true); | |
foreach ($all_mimes as $key => $value) { | |
if(array_search($mime,$value) !== false) return $key; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment