function jpg_clean($filename, $destination, $erstellen = TRUE) {
$handle = fopen($filename, "rb");
$segment[] = fread($handle, 2);
if($segment[0] === "\xFF\xD8") {
$segment[] = fread($handle, 1);
if($segment[1] === "\xFF") {
rewind ($handle);
while(!feof($handle)) {
$daten = fread($handle, 2);
if( (preg_match("/FFE[1-9a-zA-Z]{1,1}/i",bin2hex($daten))) || ($daten === "\xFF\xFE") ) {
$position = ftell($handle);
$size = fread($handle, 2);
$newsize = 256 * ord($size{0}) + ord($size{1});
$newpos = $position + $newsize;
fseek($handle, $newpos);
}
else {
$newfile[] = $daten;
}
}
fclose($handle);
$newfile = implode('',$newfile);
if($erstellen === TRUE) {
$handle = fopen($destination, "wb");
fwrite($handle, $newfile);
fclose($handle);
return TRUE;
}
else {
return $newfile;
}
}
else {
return FALSE;
}
}
else {
return FALSE;
}
}