|
1 |
| -Piexifjs |
| 1 | +Piexif-ts |
2 | 2 | ========
|
3 | 3 |
|
4 |
| -**Node.js** |**browser** |
5 |
| --------------------------------------------------------------------------------------------------------------------|----------- |
6 |
| -[](https://travis-ci.org/hMatoba/piexifjs)|[](https://circleci.com/gh/hMatoba/piexifjs/tree/2.0) |
7 |
| - |
8 | 4 | This repository is forked from [piexifjs](https://github.com/hMatoba/piexifjs) and all praise should go to the creator of this great library.
|
9 |
| - |
10 |
| -``` |
11 |
| -npm install piexif-ts |
12 |
| -``` |
| 5 | + |
| 6 | +Fix of the Typescript version of the original [piexifjs](https://github.com/hMatoba/piexifjs) as I was having trouble using it. See original documentation for how to use it. |
13 | 7 |
|
14 | 8 | How to Use
|
15 | 9 | ----------
|
16 | 10 |
|
| 11 | +It's very similar to the javascript library, but with some slight differences. Below is an example of how you can use this: |
| 12 | + |
| 13 | +```typescript |
| 14 | +import piexif, { IExif, IExifElement, TagValues } from 'piexif-ts'; |
| 15 | + |
| 16 | +var file = evt.target.files[0]; |
| 17 | + |
| 18 | +var zeroth: IExifElement = {}; |
| 19 | +var exif: IExifElement = {}; |
| 20 | +var gps: IExifElement = {}; |
| 21 | +zeroth[TagValues.ImageIFD.Make] = "Make"; |
| 22 | +zeroth[TagValues.ImageIFD.XResolution] = [777, 1]; |
| 23 | +zeroth[TagValues.ImageIFD.YResolution] = [777, 1]; |
| 24 | +zeroth[TagValues.ImageIFD.Software] = "Piexifjs"; |
| 25 | +exif[TagValues.ExifIFD.DateTimeOriginal] = "2010:10:10 10:10:10"; |
| 26 | +exif[TagValues.ExifIFD.LensMake] = "LensMake"; |
| 27 | +exif[TagValues.ExifIFD.Sharpness] = 777; |
| 28 | +exif[TagValues.ExifIFD.LensSpecification] = [[1, 1], [1, 1], [1, 1], [1, 1]]; |
| 29 | +gps[TagValues.GPSIFD.GPSVersionID] = [7, 7, 7, 7]; |
| 30 | +gps[TagValues.GPSIFD.GPSDateStamp] = "1999:99:99 99:99:99"; |
| 31 | +var exifObj: IExif = {"0th":zeroth, "Exif":exif, "GPS":gps}; |
| 32 | +var exifStr = piexif.dump(exifObj); |
| 33 | + |
| 34 | +var reader = new FileReader(); |
| 35 | +reader.onload = function(e) { |
| 36 | + var inserted = piexif.insert(exifStr, e.target.result); |
| 37 | + |
| 38 | + var image = new Image(); |
| 39 | + image.src = inserted; |
| 40 | + image.width = 200; |
| 41 | + var el = $("<div></div>").append(image); |
| 42 | + $("#resized").prepend(el); |
| 43 | + |
| 44 | +}; |
| 45 | +reader.readAsDataURL(file); |
| 46 | +``` |
| 47 | + |
| 48 | +Note also that in `tsconfig.json` the following setting needs to be set to `commonjs` for some reason. I am not sure why, so if someone could explain me, please do. |
| 49 | + |
| 50 | +```json |
| 51 | +{ |
| 52 | +... |
| 53 | + "compilerOptions": { |
| 54 | + "module": "commonjs", |
| 55 | + ... |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
| 59 | + |
17 | 60 | [Read the Docs](https://piexifjs.readthedocs.io/en/2.0/index.html)
|
18 | 61 |
|
19 | 62 | Dependency
|
|
0 commit comments