JPEG File EXIF Information
You can access and modify EXIF information in a JPEG file (with the common .jpg
extension).
The Exif API is mandatory for Tizen Mobile, Wearable, and TV profiles, which means that it is supported on all mobile, wearable, and TV devices. All mandatory APIs are supported on the Tizen emulators.
The main features of the Exif API include the following:
-
Loading EXIF information
You can retrieve EXIF information from a JPEG file. You can also retrieve the thumbnail image of the file.
-
Adding EXIF information
You can save EXIF information to a JPEG file which currently has no EXIF information.
-
Updating EXIF information
You can modify EXIF information in a JPEG file and save the file.
-
Copying EXIF information
You can copy EXIF information from one JPEG file to another.
Load the EXIF data
Learning how to retrieve EXIF data from JPEG files is a useful content management skill:
-
To retrieve the EXIF data from an image file, you need the absolute URI of the file (for example
file:///opt/usr/media/Images/tizen.jpg
). Thetizen.filesystem.resolve()
andtoURI()
methods can be used to convert a virtual path to a URI:var fileURI = ''; function resolveSuccess(file) { fileURI = file.toURI(); console.log('Successfully resolved file: ' + fileURI); } function resolveFail(error) { console.log('resolve() error occurred: ' + error.name + ' with message: ' + error.message); } tizen.filesystem.resolve('images/tizen.jpg', resolveSuccess, resolveFail);
-
With a valid
File
object, use thegetExifInfo()
method of theExifManager
interface (in mobile, wearable, and TV applications) and pass the URI to the method:function onSuccess(exifInfo) { console.log('Successfully got EXIF information object'); } function onError(error) { console.log('Error occurred: ' + error.name + ' with message:' + error.message); } tizen.exif.getExifInfo(fileURI, onSuccess, onError);
With a valid
exifInfo
object, you can access variousExifInformation
attributes (in mobile, wearable, and TV applications), such as width, height, orientation, and flash. -
To retrieve the EXIF thumbnail from the image, follow these steps:
-
Resolve the input JPEG file:
var fileURI = ''; tizen.filesystem.resolve('images/tizen.jpg', resolveSuccess, resolveFail);
-
Use the
getThumbnail()
method to retrieve the thumbnail:function onSuccess(thumbData) { console.log('Got thumbnail data from EXIF stored in JPEG file'); if (thumbData) { var img = new Image(); img.src = thumbData; document.body.appendChild(img); } } function onError(error) { console.log('Error occurred: ' + error.name + ' with message: ' + error.message); } function resolveSuccess(file) { fileURI = file.toURI(); console.log('Successfully resolved file: ' + file.toURI()); tizen.exif.getThumbnail(fileURI, onSuccess, onError); }
-
Add EXIF data
Learning how to add EXIF data to JPEG files is a useful content management skill:
-
Create a new
ExifInformation
object (in mobile, wearable, and TV applications):var myNewExif = new tizen.ExifInformation(); myNewExif.userComment = 'Photo taken on Charles Bridge in Prague'; myNewExif.gpsLocation = new tizen.SimpleCoordinates(50.086447, 14.411856);
-
Resolve the virtual path to the output JPEG file and get the URI:
var fileNoExifURI = ''; function resolveSuccess(file) { fileNoExifURI = file.toURI(); console.log('Successfully resolved file: ' + fileNoExifURI); } function resolveFail(error) { console.log('Error occurred: ' + error.name + ' with message: ' + error.message); } tizen.filesystem.resolve('images/image_without_exif.jpg', resolveSuccess, resolveFail);
-
When you have a valid URI to the file, set it in the
myNewExif
object and call thesaveExifInfo()
method of theExifManager
interface (in mobile, wearable, and TV applications):function onSaveSuccess() { console.log('Successfully saved EXIF information to JPEG file'); } function onSaveError(error) { console.log('Error occurred:' + error.name + ' with message:' + error.message); } myNewExif.uri = fileNoExifURI; tizen.exif.saveExifInfo(myNewExif, onSaveSuccess, onSaveError);
Update the EXIF data
Learning how to update EXIF data in JPEG files is a useful content management skill:
-
To update the EXIF data, load the
ExifInformation
object (in mobile, wearable, and TV applications) from the file and change the values of the object properties.You can remove information from the file by setting the property to
null
:function getSuccess(exifInfo) { exifInfo.orientation = 'FLIP_HORIZONTAL'; exifInfo.userComment = 'Great times!'; /* Remove basic GPS information */ exifInfo.gpsLocation = null; exifInfo.gpsAltitude = null; } tizen.filesystem.resolve('images/photo.jpg', function(file) { tizen.exif.getExifInfo(file.toURI(), getSuccess); });
-
After updating the property values, use the
saveExifInfo()
method of theExifManager
interface (in mobile, wearable, and TV applications) to save the changes to the file:function saveSuccess(exifInfo) { console.log('new EXIF saved'); } tizen.exif.saveExifInfo(exifInfo, saveSuccess);
Copy the EXIF data
Learning how to copy EXIF data between JPEG files is a useful content management skill:
-
Get the
ExifInformation
object (in mobile, wearable, and TV applications) and resolve the output file, and then change thesourceExifInfo.uri
attribute to point to the output JPEG file:var sourceExifInfo = null; function resolveOutSuccess(outFile) { console.log('Successfully resolved file: ' + outFile.toURI()); sourceExifInfo.uri = outFile.toURI(); } function resolveOutFail(error) { console.log('Error occurred: ' + error.name + ' with message: ' + error.message); } function onSuccess(exifInfo) { console.log('Successfully got EXIF information object'); sourceExifInfo = exifInfo; tizen.filesystem.resolve('images/image_without_exif.jpg', resolveOutSuccess, resolveOutFail); } tizen.exif.getExifInfo(fileURI, onSuccess);
-
Use the
saveExifInfo()
method of theExifManager
interface (in mobile, wearable, and TV applications) to save the changes in the output JPEG file:function onSaveSuccess() { console.log('Successfully saved EXIF information to JPEG file'); } function onSaveError(error) { console.log('Error occurred:' + error.name + ' with message:' + error.message); } function resolveOutSuccess(outFile) { console.log('Successfully resolved file: ' + outFile.toURI()); sourceExifInfo.uri = outFile.toURI(); tizen.exif.saveExifInfo(sourceExifInfo, onSaveSuccess, onSaveError); }
Related information
- Dependencies
- Tizen 2.4 and Higher for Mobile
- Tizen 2.3.1 and Higher for Wearable
- Tizen 3.0 and Higher for TV