hMatoba / piexifjs

Read and modify exif in client-side or server-side JavaScript.
MIT License
572 stars 119 forks source link

Uncaught Given data is not jpeg #17

Closed leknoppix closed 8 years ago

leknoppix commented 8 years ago

Hello

i will try to use the function remove, but i have an error when I choose a picture. I use like this: var piexifjs = require('piexifjs'); piexifjs.remove(file); Where file is mypicture: "C:\Users\leknoppix\Pictures\10 ans bac 2005\P1050914 - Copie.jpeg"

The console.log give this to return: Given data is not jpeg.

I don't understand where is the problem. I think that is me but I don't look the solve.

hMatoba commented 8 years ago

Could you upload the jpeg?

leknoppix commented 8 years ago

p1050914

I use this but, I think that is not correct: var jpeg = fs.readFileSync(file); var data = jpeg.toString("binary"); piexifjs.remove(data);

EDIT: I this I have found a solution:

var jpeg = fs.readFileSync(file);
var data = jpeg.toString("binary"); 
data = piexifjs.remove(data);
var newJpeg = new Buffer(data, "binary");
fs.writeFileSync(file + ".test.jpg", newJpeg);
hMatoba commented 8 years ago

It means solved?

leknoppix commented 8 years ago

Yes and No. When I use a picture without EXIF, i obtin Uncaught Exif not found.

A idea?

hMatoba commented 8 years ago

No error ocured.

var piexif = require("piexifjs");
var fs = require("fs");

var filename1 = "in.jpg";

var jpeg = fs.readFileSync(filename1);
var data = jpeg.toString("binary");
var new = piexif.remove(data);
hMatoba commented 8 years ago

use "try catch".

leknoppix commented 8 years ago

Thank

lakuhana commented 1 year ago

This's the answer to the question : https://github.com/hMatoba/Piexif/issues/30#issuecomment-275818092 Thumbnail information is wrong. If a jpeg has thumbnail, it must have 1st IFD and JPEGInterchangeFormatLength in Exif IFD(exif["Exif"][piexif.ExifIFD.JPEGInterchangeFormatLength]) value. JPEGInterchangeFormatLength means byte size of thumbnail. Your image has thumbnail's information, but it shows thumbnail's size as byte is zero, so remove thumbnail's information.

del exif["1st"]
del exif["thumbnail"]
piexif.dump(exif)