From 8bae165bb76e122d2f1181f938aa0f92fa0b97cd Mon Sep 17 00:00:00 2001 From: Chih-Ching Chang Date: Mon, 13 Nov 2017 20:59:02 +0800 Subject: [PATCH] add more exif checks when removing exif --- piexif.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/piexif.js b/piexif.js index c8b61dc..27a41b6 100644 --- a/piexif.js +++ b/piexif.js @@ -39,17 +39,12 @@ SOFTWARE. } var segments = splitIntoSegments(jpeg); - if (segments[1].slice(0, 2) == "\xff\xe1" && - segments[1].slice(4, 10) == "Exif\x00\x00") { - segments = [segments[0]].concat(segments.slice(2)); - } else if (segments[2].slice(0, 2) == "\xff\xe1" && - segments[2].slice(4, 10) == "Exif\x00\x00") { - segments = segments.slice(0, 2).concat(segments.slice(3)); - } else { - throw("Exif not found."); - } + var newSegments = segments.filter(function(seg){ + return !(seg.slice(0, 2) == "\xff\xe1" && + seg.slice(4, 10) == "Exif\x00\x00"); + }); - var new_data = segments.join(""); + var new_data = newSegments.join(""); if (b64) { new_data = "data:image/jpeg;base64," + btoa(new_data); }