function move_to_bartlett($tmp_file, $newfile) { $bartlett = array( 0xff, 0xe1, //APP1 0x00, 0xA4, //size, 2nd octet was b8 0x45, 0x78, 0x69, 0x66, 0x00, 0x00, //exif prolog 0x49, 0x49, //motorola endian 0x2a, 0x00, //42 0x08, 0x00, 0x00, 0x00, // offset of 0th ifd //0th ifd 0x01, 0x00, //IOP# num ifds to follow 0x25, 0x88, //gps tag 0x04, 0x00, //type long 0x01, 0x00, 0x00, 0x00, //count 0x1A, 0x00, 0x00, 0x00, //offset of gps ifd 0x00, 0x00, 0x00, 0x00, //next ifd offset 0x06, 0x00, //num GPS ifd's 0x00, 0x00, // tag: version 0x01, 0x00, // type: 8 bits 0x04, 0x00, 0x00, 0x00, //count 0x02, 0x02, 0x00, 0x00, //value 0x06, 0x00, // altitude tag 0x05, 0x00, //type rational 0x01, 0x00, 0x00, 0x00, //count 0x64, 0x00, 0x00, 0x00, //offset 0x02, 0x00, //latitude tag 0x05, 0x00, //type rational 0x03, 0x00, 0x00, 0x00, //count 0x6C, 0x00, 0x00, 0x00, //offset 0x04, 0x00, //longitude tag 0x05, 0x00, //type rational 0x03, 0x00, 0x00, 0x00, //count 0x84, 0x00, 0x00, 0x00, //offset 0x01, 0x00, //latref tag 0x02, 0x00, //ascii type 0x02, 0x00, 0x00, 0x00, //count 0x4e, 0x00, 0x00, 0x00, //"N" 0x03, 0x00, //longref tag 0x02, 0x00, //ascii type 0x02, 0x00, 0x00, 0x00, //count 0x57, 0x00, 0x00, 0x00, // "W" 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, //altitude 0x29, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, //lat 0x3A, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, //long 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00); $found_oldexif=FALSE; $in_stream=fopen($tmp_file,"rb"); $out_stream=fopen($newfile,"wb"); //read 2 bytes $buffer=fread($in_stream,2); fwrite($out_stream,$buffer,2); $thebyte=0; $totalbytesread=0; foreach ($bartlett as $bartlettbyte) { fwrite($out_stream,chr($bartlettbyte),1); } while (!feof($in_stream) && $found_oldexif==FALSE ){ //should have found any exif by ... $thebyte=fread($in_stream,1); if(ord($thebyte)==0xff) { //error_log ("hit ff"); if ((ord($thebyte=fread($in_stream,1)))==0xe1) { //error_log ("hit ff e1"); //skip the next n bytes where n=.. $lh=0; $ll=0; $lh=ord(fread($in_stream,1)); $ll=ord(fread($in_stream,1)); $itemlen = ($lh << 8) | $ll; //error_log("itemlen is $itemlen"); $discard=fread($in_stream,($itemlen-2)); //-2 cause already 2 in $found_oldexif=TRUE; } else { fwrite($out_stream,chr(0xff)); fwrite($out_stream,$thebyte); $totalbytesread+=2; } } else { fwrite($out_stream,$thebyte,1); if ($totalbytesread++>4096) { //error_log("hit 4096 bytes"); break; } } }//end while //read the rest while (!feof($in_stream)) { $buffer=fread($in_stream,8192); fwrite($out_stream, $buffer); } fclose ($in_stream); fclose ($out_stream); @unlink($tmp_file); return TRUE; }