PHP fix image bytes -



i'm gonna strart use case, before i'll explane problem i'm running in to.

i'm building mobile application using phonegap framework.
application need upload file (a picture made camera).
on platforms can image base64 encoded image.
can send server, , can decode , save it. (and other funcy stuff it's qr code).

now on symbian, can't base64 string, , can uri image. isn't problem, becouse can use xmlhttprequest image data , encode base64 using javascript.

this methode works, gives me problem.
symbian browser appears have bug. it's webkit based browser 2005 (yes, it's old, on newest s60 phones).
bug converts characters doesn't know (not in utf-8 table) 2 bytes. if remember correctly above 127.

i have tried fix bug using javascript, no go (btw, canvas , getbinaries or not supported canvas 2d not supported browser).

so, try build workaround in php fix bytes. have right now, though it's not working:

function getvalidbin($bin, $offset = 0) {     $binlength = sizeof($bin);     ($i = $offset; $i<=$binlength; $i++) {         if ($i == $binlength) {             return false;         }         if ($bin[$i] < 127) {              $bint = $bin[$i] + $bin[$i+1];             $bin2 = $bin;             $bin2[$i] = $bint;             $bin2[$i+1] = null;             if (imagecreatefromstring($bin2) != false) {                 return $bin2;             } else {                 $bin3 = getvalidbin($bin2, $i);                  if ($bin3 != false) {                     return $bin3;                 }             }         }     } } 

this function not working reason. following warnings:

warning: imagecreatefromstring() [function.imagecreatefromstring]: data not in recognized format in /opt/content/erik/omnicol/html/ws/services/qrdecoder/qrdecoder.php on line 98

and get:

fatal error: maximum function nesting level of '100' reached, aborting! in /opt/content/erik/omnicol/html/ws/services/qrdecoder/qrdecoder.php on line 87

this last 1 quite easy solve, think, think i'de post anyway.

now, question are:
on right track?
how solve warning?

thanks lot in advance,
erik

p.s. sorry if english bad. i'm not native speaker, i'm dutch.
p.s.2 bug talking one: http://markmail.org/message/iosbn3rbcgu5k6qt

edit: solution max of 100 depth harder thought be. on great too.

why trying create image after each , every byte? , recursion for? can't run on string , fix double-bytes? this:

function getvalidbin($s) {     $new_s = '';     ($i = 0; $i < strlen($bin) ; $i++)     {         $char = $s{$i};         if (ord($char) > 127)         {             $char = chr(ord($char) + ord($s{$i}));             $i++;         }         $new_s .= $char;     } } 

you have put in base64-decoded string.

i assumed line

$bint = $bin[$i] + $bin[$i+1]; 

was supposed mean "if there character code > 127, add , next character code , use single character" , assumed approach want (we can't know don't know data).


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -