Giter VIP home page Giter VIP logo

piexifjs's Introduction

Piexifjs

image

image

Read and modify exif. Library to modify exif in JS(both client-side and Node.js). http://piexifjs.readthedocs.org/en/latest/index.html

Notice and Warning!

We are implementing v2.0. This version would include a few big changes. If you won't ready to use, don't update this library.

` npm install [email protected]`

Thank you for using piexifjs!

How to Use

  • var exifObj = piexif.load(jpegData) - Get exif data as object. jpegData must be a string that starts with "data:image/jpeg;base64,"(DataURL), "\xff\xd8", or "Exif".
  • var exifStr = piexif.dump(exifObj) - Get exif as string to insert into JPEG.
  • piexif.insert(exifStr, jpegData) - Insert exif into JPEG. If jpegData is DataURL, returns JPEG as DataURL. Else if jpegData is binary as string, returns JPEG as binary as string.
  • piexif.remove(jpegData) - Remove exif from JPEG. If jpegData is DataURL, returns JPEG as DataURL. Else if jpegData is binary as string, returns JPEG as binary as string.

Use with File API or Canvas API.

Example

<input type="file" id="files" />
<script src="/js/piexif.js" />
<script>
function handleFileSelect(evt) {
    var file = evt.target.files[0];

    var zeroth = {};
    var exif = {};
    var gps = {};
    zeroth[piexif.ImageIFD.Make] = "Make";
    zeroth[piexif.ImageIFD.XResolution] = [777, 1];
    zeroth[piexif.ImageIFD.YResolution] = [777, 1];
    zeroth[piexif.ImageIFD.Software] = "Piexifjs";
    exif[piexif.ExifIFD.DateTimeOriginal] = "2010:10:10 10:10:10";
    exif[piexif.ExifIFD.LensMake] = "LensMake";
    exif[piexif.ExifIFD.Sharpness] = 777;
    exif[piexif.ExifIFD.LensSpecification] = [[1, 1], [1, 1], [1, 1], [1, 1]];
    gps[piexif.GPSIFD.GPSVersionID] = [7, 7, 7, 7];
    gps[piexif.GPSIFD.GPSDateStamp] = "1999:99:99 99:99:99";
    var exifObj = {"0th":zeroth, "Exif":exif, "GPS":gps};
    var exifStr = piexif.dump(exifObj);

    var reader = new FileReader();
    reader.onload = function(e) {
        var inserted = piexif.insert(exifStr, e.target.result);

        var image = new Image();
        image.src = inserted;
        image.width = 200;
        var el = $("<div></div>").append(image);
        $("#resized").prepend(el);

    };
    reader.readAsDataURL(file);
}

document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>

Dependency

No dependency. Piexifjs just needs standard JavaScript environment.

Environment

Both client-side and server-side. Standard browsers(Tested on IE11, Opera28, and PhantomJS) and Node.js.

Issues

Give me details. Environment, code, input, output. I can do nothing with abstract.

License

This software is released under the MIT License, see LICENSE.txt.

piexifjs's People

Contributors

azure-pipelines[bot] avatar chitchu avatar eyeccc avatar hlnlwj avatar hmatoba avatar jonathanargentiero avatar jumoog avatar kaleworsley avatar kratico avatar lahdekorpi avatar matt-tingen avatar micahjon avatar ronald avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

piexifjs's Issues

Uncaught Given data is not jpeg

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.

can't figure out how to add info to BYTE type fields

Hi,

I have been trying to figure out the way to convert a string for XPSubject into the required format.
Can anyone please provide more guidance / examples on how the conversion between BYTE to javascrpt Int works ? ( i am considering to put text into subject )

thank you

Manipulate XMP metadata

It is not clear if this library can be used to read and manipulate XMP metadata.

If not, is there any plan to support XMP?

jpeg.slice is not a function - I got this error

Hello,

I used this code for modify exif and I got the error "jpeg.slice is not a function" when
var exifModified = piexif.insert(exifBytes, canvas);
Uncaught (in promise) TypeError: jpeg.slice is not a function
at Object.that.insert (piexif.js:61)
at html2canvas.then.canvas (indexh.php:57)
at

Below is my code:

function exportPicture()
{
var ld=document.getElementsByClassName("gascuns");
ld.className="garatat";
var ndom=document.getElementsByClassName("aratat");
var el = document.getElementById(ndom[0].id);
html2canvas(document.querySelector('#'+ndom[0].id)).then(canvas => {
var a = document.createElement('a');
a.href = canvas.toDataURL("image/jpg").replace("image/jpg", "image/octet-stream");
var zerothIfd = {};
var exifIfd = {};
var gpsIfd = {};
zerothIfd[piexif.ImageIFD.Make] = "Maker Name";
zerothIfd[piexif.ImageIFD.XResolution] = [300, 1];
zerothIfd[piexif.ImageIFD.YResolution] = [300, 1];
zerothIfd[piexif.ImageIFD.Software] = "Piexifjs";
exifIfd[piexif.ExifIFD.DateTimeOriginal] = "2018:10:10 10:10:10";
exifIfd[piexif.ExifIFD.LensMake] = "Lens Maker";
exifIfd[piexif.ExifIFD.Sharpness] = 777;
exifIfd[piexif.ExifIFD.LensSpecification] = [[1, 1], [1, 1], [1, 1], [1, 1]];
gpsIfd[piexif.GPSIFD.GPSVersionID] = [7, 7, 7, 7];
gpsIfd[piexif.GPSIFD.GPSDateStamp] = "2018:99:99 99:99:99";
var exifObj = {"0th":zerothIfd, "Exif":exifIfd, "GPS":gpsIfd};
var exifBytes = piexif.dump(exifObj);
var exifModified = piexif.insert(exifBytes, canvas); //here I got the error jpeg.slice is not a function
base_image = new Image();
base_image.src = a.href;
base_image.onload = function(){
context = canvas.getContext('2d');
context.drawImage(base_image, 0,0);
saveCanvas(canvas);
};
});
ld.className="gascuns";
}

      function saveCanvas(x_canvas){x_canvas.toBlob(function(blob) {saveAs(blob, "screenshot.JPG");},"image/jpeg");}

GPSLatitude, GPSLongitude, GPSTimeStamp truncated.

Hi, it seems to be there a problem with data from tags GPSLatitude, GPSLongitude and GPSTimeStamp.
Image attached show the exif object submitted to insert method of library and how is it read by load method.

piexifjs_color

By specifics GPSLatitude (2), GPSLongitude (4) and GPSTimeStamp (7) fields expect 3 values.
When i try to read them field are truncated: only 2 values of 3 are present.

Thanks!

Improve documentation

Hi,
First and foremost, thanks for this great library!
While I think the code is generally written well, I saw that in order to use this library I need to read it after reading the documentation as I didn't find what I was looking for in the documentation.
Furthermore, intellisense is not available and this too would be extremely helpful.
DefinitelyTyped is a project that is used to create intellisense to javascript libraries for TypeScript, which is currently used by Google and Microsoft.

A use case for example:
Get GPS coordinates from exif data.
The currently documentation only specify a method in the helper to write GPS coordinates, however, the code has the opposite method as well, but it can't be found in the docs and only looking at the code can reveal it.

Problem when reading or writing in Chinese

Hello, gays I love this library,it works well;
but i met some problems, it can not read or write in Chines;
For example:
I wrote "这里是中文" in "ImageIFD.Make",but i got an error info "è¿�é��æ�¯ä¸­æ��"
so how can i solve this problem;
thank you again;
image

Lost / modified fields setting GPS to {}

I am using piexifjs to scrub GPS data. After loading the exif data with .load I set the GPS field to {} and then wrote the modified data with .insert. The GPS fields are correctly removed however I've noticed some other unexpected modifications to the output exif data after comparing the resulting image with the original using exiftool.

  • EXIF lost the Interoperability Version field
  • The Scene Type field was changed from Directly photographed to Unknown (49)
  • The Thumbnail Offset field was changed from 1160 to 906 (but i suspect this is expected since there are no longer all the GPS fields that were originally present)

Ios exif is null but work on android with same jpg file

Hello.
I use this lib to read exif from jpg, thanks for the nice work.
It work very well on android but not on IOS (tested with iphone 5)

I use the same JPG file with exif inside with same code on android and Ios

the JS code to Test if exif where readed good is :

  const prefixe = "data:image/jpeg;base64,";
  const srcdata = await RNFS.readFile(image.path, "base64");
  var exifObj = piexif.load(prefixe + srcdata); 
  for (var ifd in exifObj) {
     if (ifd == "thumbnail") {
     continue;
     }
     console.log("-" + ifd);
     for (var tag in exifObj[ifd]) {
     console.log("  " + piexif.TAGS[ifd][tag]["name"] + ":" + exifObj[ifd][tag]);
     }
  }
  1. IOS results :

If i log exif from piexifjs this is what i get :

  -0th
     Orientation:1
     ExifTag:38
  -Exif
     ColorSpace:1
     PixelXDimension:2448
     PixelYDimension:3264
  -GPS
  -Interop
  -1st 

If i use react-native-image-crop-picker i get good exif on Android and Ios but i need piexifs because i want to read exif, compress jpg then re write exif

log from react-native-image-crop-picker on Ios

   {Exif}:
	  ApertureValue:2.52606882168926
	  BrightnessValue:3.343102774521297
	  ColorSpace:1
	  ComponentsConfiguration:(4) [1, 2, 3, 0]
	  DateTimeDigitized:"2018:09:28 10:34:06"
	  DateTimeOriginal:"2018:09:28 10:34:06"
	  ExifVersion:(3) [2, 2, 1]
	  ExposureBiasValue:0
	  ExposureMode:0
	  ExposureProgram:2
	  ExposureTime:0.05
	  FNumber:2.4
	  Flash:24
	  FlashPixVersion:(2) [1, 0]
	  FocalLenIn35mmFilm:33
	  FocalLength:4.12
	  ISOSpeedRatings:[64]
	  LensMake:"Apple"
	  LensModel:"iPhone 5c back camera 4.12mm f/2.4"
	  ... 
  1. Android results with same jpg file with piexif

    -0th
    Make:Apple
    Model:iPhone 5c
    Orientation:1
    XResolution:72,1
    YResolution:72,1
    ResolutionUnit:2
    Software:Photos 3.0
    DateTime:2018:09:28 10:34:06
    ExifTag:198
    GPSTag:1010
    -Exif
    ExposureTime:1,20
    FNumber:12,5
    ExposureProgram:2
    ISOSpeedRatings:64
    ExifVersion:0221
    DateTimeOriginal:2018:09:28 10:34:06
    DateTimeDigitized:2018:09:28 10:34:06
    FlashpixVersion:0100
    ColorSpace:1
    PixelXDimension:2448
    PixelYDimension:3264
    SensingMethod:2
    ExposureMode:0
    WhiteBalance:0
    FocalLengthIn35mmFilm:33
    SceneCaptureType:0
    LensSpecification:103,25,103,25,12,5,12,5
    LensMake:Apple
    LensModel:iPhone 5c back camera 4.12mm f/2.4
    -GPS
    GPSLatitudeRef:N
    GPSLatitude:43,1,39,1,619,100
    GPSLongitudeRef:E
    GPSLongitude:3,1,51,1,4265,100
    GPSAltitudeRef:0
    GPSAltitude:45,1
    GPSTimeStamp:8,1,34,1,4,1
    GPSSpeedRef:K
    GPSSpeed:183,100
    GPSImgDirectionRef:T
    GPSImgDirection:21788,115
    GPSDestBearingRef:T
    GPSDestBearing:21788,115
    GPSDateStamp:2018:09:28
    GPSHPositioningError:100,1
    -Interop
    -1st

Did you think there is a fix ?

EDIT : this is my "transplante" function

  // RNFS is react-native-fs
  const srcdata = await RNFS.readFile(image.path, "base64");
  
  var srcexifs = piexif.load(prefixe + srcdata);

  //compress image
  const compressedImage = await ImageResizer.createResizedImage(image.path, 900, 900, "JPEG", 72);

  const compressedImageb64 = await RNFS.readFile(compressedImage.uri, "base64");
  // get exif to write them 
  const _zero = srcexifs["0th"];
  const _first = srcexifs["1st"];
  const _Exif = srcexifs["Exif"];
  const _GPS = srcexifs["GPS"];

  var exifObj = { "0th": _zero, "1st": _first, Exif: _Exif, GPS: _GPS };
  var exifbytes = piexif.dump(exifObj);
  //  write the exif in base64 image
  var bs64Exif = piexif.insert(exifbytes, prefixe + compressedImageb64).substring(prefixe.length);
  // write the file
  await RNFS.writeFile(compressedImage.uri, bs64Exif, "base64");

TypeError: Cannot use 'in' operator to search for '0th' in data:image...

Code failing

let exifBytes = piexifjs.dump(dataURL);

Error message

TypeError: Cannot use 'in' operator to search for '0th' in data:image...

Environment
Chrome 70
Vue 3.1.0
cmd vue-cli-service serve --watch
"piexifjs": "^1.0.4",

MDN Related error
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/in_operator_no_object

Nobody else get this error?
Fixed in piexif 2.0 ?
Scanning through the source codes I can see that the in operator is used everywhere.

Removing thumbnail from EXIF data

Hi,

I try to remove the embedded thumbnail from the EXIF data or replace it with a empty thumbnail with code like this:

var jpeg = image.buffer;
var data = jpeg.toString("binary");
var exifObj = piexif.load(data);
exifObj["0th"][piexif.ImageIFD.Model] = "FOOBAR 2";
exifObj['thumbnail'] = null;
var exifbytes = piexif.dump(exifObj);
var newData = piexif.insert(exifbytes, data);
var newJpeg = new Buffer(newData, "binary");

Unfortunately the thumbnail stays in the resulting image files. Can you give me any hint on what I'm doing wrong here?

getting RuntimeError: saveJpeg is not defined on CanvasSample.html

Hi Matoba-san and thank you for this wonderful tool! I am new to JavaScript and trying to learn. I hope to use your tool to better ensure digital privacy for photos I put online.

I first tried getting your CanvasSample working by publishing the file through my gh-pages account and referencing the raw version of your piexif.js file. This didn't seem to be working as expected. I then tried porting your work into a JavaScript notebook called Observablehq, which revealed a RuntimeError: saveJpeg is not defined.

Since I used npm for the port ([email protected]), I wonder -- did something change in your piexif.js file so that you no longer use saveJpeg? Could that be the reason why the example doesn't work for me?

Thanks again for your time and for this tool!

Set latest tag to v1.x on npm

Currently, npm install piexifjs will install a beta version.
When you want to install stable version, you run npm install piexifjs@^1.
However, it causes confusion.

Please consider to use npm dist-tag.
npm dist-tag can assign a tag (e.g. dev, beta, latest) to the specific version.
For example, you run npm dist-tag add [email protected] latest, everyone can install v1.0.4 via only npm install piexifjs.
And, you run npm dist-tag add [email protected] beta, everyone can install v2.0.0-beta.7 via npm install piexifjs@beta.
See also, https://docs.npmjs.com/cli/dist-tag

And also, when you publish new beta version, you can run npm publish --tag beta.
See https://docs.npmjs.com/cli/publish


Because English is not good enough, I write it in Japanese.
英語が不得意なため、日本語でも書かせていただきます。

現在、piexifjs は、バージョンを指定しない場合、β版がインストールされるようになっています。
しかし、実用的には標準で安定版がインストールされるのが良いかと思われます。

解決方法としては、 npm dist-tag で特定バージョンにタグをつける方法があります。
(詳しくは https://docs.npmjs.com/cli/dist-tag をご覧ください)

npm は、バージョン指定をしない場合、 latest タグに紐付いたものをインストールします。
そのため、npm dist-tag add [email protected] latest としていただけると、npm install piexifjs で安定版が入るようになります。
もちろん、同様に beta タグを付けるようにすれば、 npm install piexifjs@beta でインストールできます。

また、次のβ版を公開するときに npm publish --tag beta とすれば、β版を更新できます。
こちらも https://docs.npmjs.com/cli/publish を参照してください。

ぜひ、ご一考いただければ幸いです。

'constants' and 'Tags' missing in npm package

I have problems with 'get-exif' package related to piexifs (see get-exif issue #1).
The package 'get-exif' uses 'piexifjs:2.0.0-beta.7'.

Tracing down the messages I noticed that the exports in the 'piexifjs' npm package are missing the 'export.constants' and the 'export.Tags'.

As I never created a npm package I don't know, if this is by design or if something happened publishing the 'piexifjs' npm package.

By the way: the same is true for 'piexifjs:2.0.0-beta.9'.

Problem importing 2.0 beta

I've tried to use the latest version but I wan't able to use it like I did with 1.0.4:
I'm using webpack.
this doesn't work:
import piexif from "piexifjs";
Also this didn't work:
import * as piexif from "piexifjs";
I don't have other ideas I can try :-(

Multiple cases in documentation

Hi, the following documentation has a redundant if == 3:
Would be better to write it as switch case...
https://piexifjs.readthedocs.io/en/latest/sample.html#generates-rotated-jpeg

...
if (orientation == 2) {
                    x = -canvas.width;
                    ctx.scale(-1, 1);
                } else if (orientation == 3) {
                    x = -canvas.width;
                    y = -canvas.height;
                    ctx.scale(-1, -1);
                } else if (orientation == 3) {
                    x = -canvas.width;
                    y = -canvas.height;
                    ctx.scale(-1, -1);
                } else if (orientation == 4) {
                    y = -canvas.height;
                    ctx.scale(1, -1);
                } else if (orientation == 5)
...

JPEG QUALITY BY DEFAULT AT 1.0

Exif writing is fine, but jpg output quality is 100% or 1.0 whereas firefox and chrome exports at 0.92. So conflict of sizes may arise.

Not writing offset of next IFD

What should be happening:

As per the TIFF documentation, each IFD should end with:

OFFSET - Count TYPE - Description
0002h + "NUM"*12 - 1 dword - Offset of next IFD in file, 0 if none follow

The key part here is the 0 if none follow.

What is actually happening:

Piexifjs is not writing this value at all meaning several EXIF parsers (such as PHP's Pel library) will attempt to read the "four bytes over" information as an offset for the next IFD.

To reproduce the issue:

  1. Load, dump and insert EXIF for any image with GPS EXIF
  2. Open the image with PHP's Pel library, in my case I receive the following error:
#0 vendor\lsolesen\pel\src\PelDataWindow.php(424): lsolesen\pel\PelDataWindow->validateOffset(-277)
#1 vendor\lsolesen\pel\src\PelIfd.php(272): lsolesen\pel\PelDataWindow->getLong(-277)
#2 vendor\lsolesen\pel\src\PelIfd.php(285): lsolesen\pel\PelIfd->load(Object(lsolesen\pel\PelDataWindow), 35)
#3 vendor\lsolesen\pel\src\PelIfd.php(221): lsolesen\pel\PelIfd->load(Object(lsolesen\pel\PelDataWindow), 226)
#4 vendor\lsolesen\pel\src\PelTiff.php(159): lsolesen\pel\PelIfd->load(Object(lsolesen\pel\PelDataWindow), 10)
#5 vendor\lsolesen\pel\src\PelExif.php(108): lsolesen\pel\PelTiff->load(Object(lsolesen\pel\PelDataWindow))
#6 vendor\lsolesen\pel\src\PelJpeg.php(216): lsolesen\pel\PelExif->load(Object(lsolesen\pel\PelDataWindow))
#7 vendor\lsolesen\pel\src\PelJpeg.php(286): lsolesen\pel\PelJpeg->load(Object(lsolesen\pel\PelDataWindow))
#8 vendor\lsolesen\pel\src\PelJpeg.php(123): lsolesen\pel\PelJpeg->loadFile('...')

Alternatively, you can compare the raw binary before and after parsing the image with piexifjs and you will notice it strips out the 00 00 00 00 that separates the entries (key, type, length & value) from the overflow values (greater than 4 bytes).

I have implemented a temporary fix with the following:

function _dict_to_bytes(ifd_dict, ifd, ifd_offset) {
        var TIFF_HEADER_LENGTH = 8;
        var tag_count = Object.keys(ifd_dict).length;
        var entry_header = pack(">H", [tag_count]);
        var entries_length;
        if (["0th", "1st"].indexOf(ifd) > -1) {
            entries_length = 2 + tag_count * 12 + 4;
        } else {
            entries_length = 2 + tag_count * 12;
        }
        var entries = "";
        var values = "\x00\x00\x00\x00"; // Updated this line from an empty string
        var key;

However, this adds two trailing zeros after the 0th IFD as the library seems to be including this value only on the first.

I am very new to TIFF and EXIF standards so take all of this with a grain of salt. Is there a more permanent solution to this issue?

Massive memory usage when reading exif data

I am currently using piexif in an Ionic application for reading and writing exif data, and have noticed that when I call piexif.load on an image a disproportionate amount of memory is used. For example, reading the exif data on a 3mb image results in a peak memory usage of 300mb. When used on a larger image, such as a panorama, memory usage often exceeds 600mb and results in the app crashing.

I'm not really sure where to start debugging this issue. It is possible that this is an edge case when piexif is used with Ionic, but I was consistently able to reproduce this behavior with a variety of images. Any thoughts or insights as to what in piexif would be resulting in this behavior?

Thanks for creating and sharing such a great library!

IPTC

Hi hMatoba,

Not sure if this is the right way to request a feature, so please let me know how to if not.

Will there be support for IPTC tags in the near future? I have spec to convert our perl runners to nodejs and this is the best nodejs exif read and write tool I've found yet. Only problem is the lack of IPTC support which means I can't migrate to nodejs soon.

Regards
gavinvangent

Question: Does .remove retain the color profile data

I'm looking to convert JPG's to PNG's using ImageMagick's convert.exe. However, just running convert.exe input.jpg output.png will add additional EXIF metadata I don't want to the output. The convert.exe has an argument called -strip that removes the EXIF data, all comments, and all profiles. That includes removing the color profile data, and since I want the output to be lossless, I need to retain the color profile.

I'm looking into piexifjs as a pre-step, to remove the EXIF, then have convert.exe run to create the PNG.

The documentation for .remove doesn't go into detail as to what it removes and what it retains.

Some exif data is corrupted after using insert()

Thanks for the work,

I want to modify exif orientation, which I'm able to do for most images, but for some images some exif data (like "Make", "Model", "X-resolution", "Y-resolution") gets corrupted or lost.

So I tried to compare exif objects before and after modification on those problematic images, but when I try to get exif object using load() after inserting modified exif, I'm getting this error:

Uncaught 'unpack' error. Mismatch between symbol and string length. 2:0.

If I just take the inserted jpegData and create a blob out of it, some of exif data becomes corrupted:

Before:

screen shot 2017-02-22 at 4 35 25 pm

After:

screen shot 2017-02-22 at 4 35 57 pm

Here is the code that I used:

function modifyOrientation(file) {

  var reader = new FileReader();

  reader.onload = function(e) {

    var origDataUrl = e.target.result;
    var exif = piexif.load(origDataUrl);
    console.log(exif);

    exif['0th'][piexif.ImageIFD.Orientation] = 1; // modifying orientation
    var dump = piexif.dump(exif);
    var inserted = piexif.insert(dump, origDataUrl);

    var modifiedExif = piexif.load(inserted); // <== error thrown here
    console.log(modifiedExif);

    debugger;
  };

  reader.readAsDataURL(file);
}

and here is the sample image:

sample 2 - this night scene has sacrificed light for detail and contains no colour

'pack' error. Got invalid type argument

Hi, we're using Piexifjs in production at BeFunky (an online photo editor) and have been getting this error pretty often:
'pack' error. Got invalid type argument

I looked over the call sites of the pack() function, and my best guess is that the culprit is line 457, where _dict_to_bytes() converts raw_value to an array if its a number, but not if its any other type (string, undefined, null, etc).

I'll let you know if I'm able to get an actual stack trace, but I just wanted to pass this along in case it was an oversight. Thanks for this super handy library.

Problem when running inside cordova

I have no clue why, but the following image does not get any exif info when used inside cordova.
When using the same code on desktop browser the data is fetched correctly.
img_20190205_233435
How can I debug this?

Is v2.0 still to be released?

I saw the Beta has existed for a long time now. Are there plans to release v2.0 in the near future? Or should we stick with v1?

exif.slice is not a function

I am trying to add extracted exif object and its showing this error:

exif.slice is not a function

    that.insert = function (exif, jpeg) {
        var b64 = false;
        if (exif.slice(0, 6) != "\x45\x78\x69\x66\x00\x00") {
            throw ("Given data is not exif.");
        }

This is the basic exif object. Its same as when I got it. I have not modified it.:

{
"0th"
"1st"
"Exif"
"GPS"
"Interop"
}

any idea why?

manipulating jpeg binary strings in windows

Hi @hMatoba ,

I'm considering using this tool to edit personal photos so I'm worried about data integrity. In particular, I'm feeling hesitant/cautious on manipulating jpeg binary strings. Forgive my ignorance, but is this safe to do? And are there any edge cases or pitfalls I should be aware of?

Thanks!

Can't write EXIF data if input data differs from expected value in TAGS array.

I have an image with ProfileCopyright data ("aStringValue") set with a type of 'Ascii'.

I can read the image, get the EXIF, but when I write the EXIF to the modified file, the existing code retrieves the expected type for this field (TAGS[50942] -> "Byte") and attempt to save {50942, "Byte", "aStringValue"} which fails because "Byte" expects an Array, not a String.

I'm not familiar enough with EXIF to be sure whether the error lies in the input file or in piexeif (which is very nice, thank you). ProfileCopyright is not listed in the documentation for EXIF 2.3, but it is listed on http://www.exiv2.org/tags.html.

0th ImageDescription

The loadsample.html example doesn't show ImageDescription (270) when the image loads. I can't find a way to extract it.

Using the library I can write to 270 (zerothIfd[piexif.ImageIFD.ImageDescription] = "Description"; in the dumpsample.html file.

Is there a reason ImageDescription doesn't appear?

problem setting 0x9286 EXIF UserComment

I m having a problem setting
0x9286 UserComment (ExifIFD), this is a 2-Byte field

the first 8 characters are cut off, everyting that follows looks ok. It might be related to the 2-byte formating of the code, but I m not sure what kind of encoding this may be (UTF8?).

the UserComment output of the example below would be
' Here comes some normal text..'

`
const exifObj = piexif.load(base64Str.target.result);

// Read EXIF Orientation data.
const orientation = exifObj["0th"][piexif.ImageIFD.Orientation];

let zeroth = exifObj["0th"] //{};
let exif = exifObj["Exif"] //{};
let gps = exifObj["GPS"] //{};

zeroth[piexif.ImageIFD.Orientation] = 1
exif[37510] = '12345678 Here comes some normal text..'

const newExifObj = {"0th":zeroth, "Exif":exif, "GPS":gps};
const exifbytes = piexif.dump(newExifObj);
`

unpack error after adding and then removing exif info

I had to add/update some exif information to image and then remove all information later on. Using this library, I was able to add exif info to the image but wasn't being able to remove after adding, due to unpack: mismatch error on line 801. This issue was found for some images.

My change:
Line no 41 to 45 of piexif.js.

You check occurrence of "ÿá" character at segment index 1 and then at index 2. If found you remove that segment. However in my case, this character was occurring twice at two different segments which was causing issue.

I have written a loop to check for all such segments starting with "ÿá", and removed that segment if found. Is this approach correct?

e.g.

        var arr = []
        for (var i = 0; i < segments.length; i++){
            var item = segments[i];

            if (item.slice(0, 2) != "\xff\xe1"){
                arr.push(item)
            }
        }
        segments = arr;

This resolves error on my side for all images. But I am not sure if this is how you would have done it!

pizigani_1367_chart_1mb

Code in html:

function handleFileSelect(evt) {
    var file = evt.target.files[0];
    var reader = new FileReader();
    reader.onloadend = function(e){
        var originalData = e.target.result;
        printExif(originalData);
        originalData = updateExif(originalData)
        originalData = removeExif(originalData);
        originalData = updateExif(originalData)
        originalData = removeExif(originalData)
    };
    reader.readAsDataURL(file);
}


function updateExif(originalData){
        var allExifData = piexif.load(originalData);
        allExifData['0th'][271] = "sanjay";
        allExifData['0th'][272] = "pandey";
        allExifData['GPS'][2] = [[1,1], [2,1], [3,1]];
        allExifData['GPS'][4] = [[4,1], [5,1], [6,1]];

        var exifBytes = piexif.dump(allExifData);

        var finalData = piexif.insert(exifBytes, originalData);

        printExif(finalData);

        return finalData
}

function removeExif(originalData){
  var finalData = piexif.remove(originalData);
  printExif(finalData);

  return finalData
}

bower

This is awesome library.
Could you push it to bower?

Parse exif data to String (Cont.)

Hi, I also have the same question - I would like to read GPSLatitude and GPSLongitude, but I get [ [Array], [Array], [Array] ]. Is there any method I can call to get the actual values? I have looked at the link that you provided in another answer, http://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf, but it is 190 pages long and I could not find the answer.

After calling console.log(piexif.load(fs.readFileSync("MY_JPG.JPG").toString("binary"));
screen shot 2018-06-08 at 9 12 55 am

Add support for TypedArrays

Given the reduced memory consumption of using TypedArrays instead of UTF-16 encoded JavaScript strings, I can see this being a huge benefit for piexifjs.

Would you consider a pull-request that implemented support for this, and if so, how would you want to add it to your API? Would each of the existing functions just check the type of the input and act accordingly, or would you want separate functions for dealing with TypedArrays instead of strings?

PNG support?

What's the likelihood that piexifjs could support png? Any plans for implementing this in the future? Thanks for all the hard work, it's a really great library :)

Dead

Should probably mark this repo as dead since its no longer supported by anyone.

Parse exif data to string.

I am using your library for the first time. When I read the data, I get something like:

{
"Exif": {
"ExposureTime": [1, 800],
"FNumber": [71, 10]
}
}

My question is, how can we get the values "ExposureTime" & "FNumber" as strings? Also, there are other objects like "GPSLatitude": [ [Object], [Object], [Object] ]

Why these values are not in string, Is there any method to get them as string?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.