12

I am looking for a JavaScript mechanism to modify the image EXIF metadata info, I found plenty of JS libraries that allow me to retrieve EXIF info, but none that modify.

I am looking to modify EXIF orientation information for the image, then save it.

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
Dinesh Babu
  • 144
  • 2
  • 6

1 Answers1

2

blueimp has a library JavaScript-Load-Image that can modify/parse EXIF tag when loading the image. Here is the link to the code on GitHub

use the loadImage() function and provide the orientation optional field to modify EXIF orientation value.

document.getElementById('file-input').onchange = function (e) {
    loadImage(
        e.target.files[0],
        function (img) {
            document.body.appendChild(img);
        },
        {orientation: 3}
    );
};

Here is a list of EXIF orientation values and the specified rotation info available here: https://beradrian.wordpress.com/2008/11/14/rotate-exif-images/

  • 1 = The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side.
  • 2 = The 0th row is at the visual top of the image, and the 0th column is the visual right-hand side.
  • 3 = The 0th row is at the visual bottom of the image, and the 0th column is the visual right-hand side.
  • 4 = The 0th row is at the visual bottom of the image, and the 0th column is the visual left-hand side.
  • 5 = The 0th row is the visual left-hand side of the image, and the 0th column is the visual top.
  • 6 = The 0th row is the visual right-hand side of the image, and the 0th column is the visual top.
  • 7 = The 0th row is the visual right-hand side of the image, and the 0th column is the visual bottom.
  • 8 = The 0th row is the visual left-hand side of the image, and the 0th column is the visual bottom.
display name
  • 4,165
  • 2
  • 27
  • 52
  • 4
    That is not what this question is about, what we need is a library that can modify AND SAVE exif information to the image. – Tomas Mar 15 '15 at 21:57
  • I see. All the libraries that I know of use either Java or PHP to do so. None in JavaScript. blueimp does modify the tag onLoad. Since I don't know your use case, I could only suggest you to ask the user to save it as a file by clicking a button. This way, you create a shadow copy with correct orientation value. – display name Mar 16 '15 at 00:43
  • Actually its quite surprising since all documentation is out there, there are very advanced scripts to get the metatags, not sure why nobody just reversed it to write the metadata as well... I will end up using some server side script for the moment, but evetually want to move everythong onto client as there is no need for central storage. Usecase is simple: Generate image, write metadata and save it – Tomas Mar 16 '15 at 13:06