Giter VIP home page Giter VIP logo

goexiv's Introduction

Build Status

Go bindings for exiv2 (http://www.exiv2.org)

The library allows reading and writing EXIF and IPTC metadata to/from JPG, WEBP, and PNG images.

It is based on https://github.com/abustany/goexiv and https://github.com/gitschneider/goexiv with support added for writing the metadata and various bugfixes.

Библиотека для записи и чтения метаданных EXIF и IPTC в изображениях формата JPG, WEBP и PNG. Основана на https://github.com/abustany/goexiv и https://github.com/gitschneider/goexiv с добавленной фукнциональностью для записи метаданных и исправлением ошибок.

Requirements

A libexiv2 library v0.27 is required (this might also work with newer versions, but it hasn't been tested).

On Ubuntu, libexiv2 can be installed from the package manager (sudo apt install libexiv2-dev), but there is no guarantee it comes with the version needed. So it is safer to install it manually:

  • Download and unpack the library from https://github.com/Exiv2/exiv2/releases/tag/v0.27.2
  • Install the library (the steps are taken from libexiv2 README):
    mkdir build && cd build
    cmake .. -DCMAKE_BUILD_TYPE=Release
    cmake --build .
    sudo make install
    sudo ldconfig
    
  • It may be needed to set the following variable: export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig

Now the Go code in this project can interface with the libexiv2 library.

The installation process for other operating systems should be similar. Also, this library is tested with golang:1.13-alpine docker image, where the correct version of libexiv2 is installed with apk --update add exiv2-dev.

Usage

Basic usage:

import "github.com/kolesa-team/goexiv"

// Open an image from disk
goexivImg, err := goexiv.Open("/path/to/image.jpg")
if err != nil {
    return err
}

// Write an EXIF comment
err = goexivImg.SetMetadataString("exif", "Exif.Photo.UserComment", "A comment. Might be a JSON string. Можно писать и по-русски!")
if err != nil {
    return err
}

// Write an EXIF short integer
err = goexivImg.SetMetadataShort("exif", "Exif.Photo.ExposureProgram", "2")
if err != nil {
    return err
}

// Read metadata
err = goexivImg.ReadMetadata()
if err != nil {
    return err
}

// Read an EXIF comment
userComment, err := goexivImg.GetExifData().GetString("Exif.Photo.UserComment")
if err != nil {
    return err
}

fmt.Println(userComment)
// "A comment. Might be a JSON string. Можно писать и по-русски!"

// It is advisable to insert this line at the end of `goexivImg` lifecycle.  
// see exiv_test.go:Test_GetBytes_Goroutine
runtime.KeepAlive(goexivImg)

Changing the image metadata in memory and returning the updated image (an approach fit for a web service):

// Say we have an image in memory: var img []byte
goexivImg, err := goexiv.OpenBytes(img)
if err != nil {
    return err
}

// Write an IPTC comment
err = goexivImg.SetMetadataString("iptc", "Iptc.Application2.Caption", "A comment. Might be a JSON string.")
if err != nil {
    return err
}

// Get back the modified image, so it can now be further processed (e.g. sent over the network)
img = goexivImg.GetBytes()

Retrieving all metadata keys and values:

img.ReadMetadata()
// map[string]string
exif := img.GetExifData().AllTags()

// map[string]string
iptc := img.GetIptcData().AllTags()

A complete image processing workflow in Go can be organized with the following additional libraries:

goexiv's People

Contributors

abustany avatar antonsergeyev avatar dchesterton avatar gitschneider avatar oderwat avatar rtio avatar toaster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

oderwat rtio sanmai

goexiv's Issues

Short values related to IPTC cannot be written

Short values related to IPTC cannot be written
Iptc.Application2.RecordVersion
Iptc.Envelope.ModelVersion
etc

// Does not result in an error
err :=rimg.SetIptcString(v.Key, v.Value)
if err != nil {
dlog.Println(err.Error())
return
}

I was able to write a character string

Compilation issues with goexiv library

Hello,

With exiv2 0.28.0

I encountered an issue while trying to compile the goexiv library. I am receiving numerous errors related to the helper.cpp file. I'm not familiar with C++, but if the error is not too complex and some guidance can be provided, I am willing to attempt a PR to fix the issue. Below are the errors I am encountering:

helper.cpp:22:50: error: expected ‘)’ before ‘image’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      |                                                  ^~~~~
helper.cpp:10:30: note: in definition of macro ‘DEFINE_STRUCT’
   10 |         _##name(wrapped_type member_name) \
      |                              ^~~~~~~~~~~
helper.cpp:10:16: note: to match this ‘(’
   10 |         _##name(wrapped_type member_name) \
      |                ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp:22:41: error: ‘AutoPtr’ in ‘class Exiv2::Image’ does not name a type
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      |                                         ^~~~~~~
helper.cpp:12:9: note: in definition of macro ‘DEFINE_STRUCT’
   12 |         wrapped_type member_name; \
      |         ^~~~~~~~~~~~
helper.cpp: In constructor ‘_Exiv2Error::_Exiv2Error(const Exiv2::Error&)’:
helper.cpp:60:26: error: cannot convert ‘Exiv2::ErrorCode’ to ‘int’ in initialization
   60 |         : code(error.code())
      |                ~~~~~~~~~~^~
      |                          |
      |                          Exiv2::ErrorCode
helper.cpp: In function ‘Exiv2Image* exiv2_image_factory_open(const char*, Exiv2Error**)’:
helper.cpp:71:67: error: no matching function for call to ‘_Exiv2Image::_Exiv2Image(Exiv2::Image::UniquePtr)’
   71 |                 p = new Exiv2Image(Exiv2::ImageFactory::open(path));
      |                                                                   ^
helper.cpp:9:8: note: candidate: ‘constexpr _Exiv2Image::_Exiv2Image()’
    9 | struct _##name { \
      |        ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp:9:8: note:   candidate expects 0 arguments, 1 provided
    9 | struct _##name { \
      |        ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp:9:8: note: candidate: ‘constexpr _Exiv2Image::_Exiv2Image(const _Exiv2Image&)’
    9 | struct _##name { \
      |        ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp:9:8: note:   no known conversion for argument 1 from ‘Exiv2::Image::UniquePtr’ {aka ‘std::unique_ptr<Exiv2::Image>’} to ‘const _Exiv2Image&’
    9 | struct _##name { \
      |        ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp:9:8: note: candidate: ‘constexpr _Exiv2Image::_Exiv2Image(_Exiv2Image&&)’
    9 | struct _##name { \
      |        ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp:9:8: note:   no known conversion for argument 1 from ‘Exiv2::Image::UniquePtr’ {aka ‘std::unique_ptr<Exiv2::Image>’} to ‘_Exiv2Image&&’
    9 | struct _##name { \
      |        ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp: In function ‘Exiv2Image* exiv2_image_factory_open_bytes(const unsigned char*, long int, Exiv2Error**)’:
helper.cpp:90:74: error: no matching function for call to ‘_Exiv2Image::_Exiv2Image(Exiv2::Image::UniquePtr)’
   90 |                 p = new Exiv2Image(Exiv2::ImageFactory::open(bytes, size));
      |                                                                          ^
helper.cpp:9:8: note: candidate: ‘constexpr _Exiv2Image::_Exiv2Image()’
    9 | struct _##name { \
      |        ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp:9:8: note:   candidate expects 0 arguments, 1 provided
    9 | struct _##name { \
      |        ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp:9:8: note: candidate: ‘constexpr _Exiv2Image::_Exiv2Image(const _Exiv2Image&)’
    9 | struct _##name { \
      |        ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp:9:8: note:   no known conversion for argument 1 from ‘Exiv2::Image::UniquePtr’ {aka ‘std::unique_ptr<Exiv2::Image>’} to ‘const _Exiv2Image&’
    9 | struct _##name { \
      |        ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp:9:8: note: candidate: ‘constexpr _Exiv2Image::_Exiv2Image(_Exiv2Image&&)’
    9 | struct _##name { \
      |        ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp:9:8: note:   no known conversion for argument 1 from ‘Exiv2::Image::UniquePtr’ {aka ‘std::unique_ptr<Exiv2::Image>’} to ‘_Exiv2Image&&’
    9 | struct _##name { \
      |        ^
helper.cpp:22:1: note: in expansion of macro ‘DEFINE_STRUCT’
   22 | DEFINE_STRUCT(Exiv2Image, Exiv2::Image::AutoPtr, image);
      | ^~~~~~~~~~~~~
helper.cpp: In function ‘void exiv2_image_read_metadata(Exiv2Image*, Exiv2Error**)’:
helper.cpp:107:22: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  107 |                 img->image->readMetadata();
      |                      ^~~~~
helper.cpp: In function ‘void exiv2_image_set_exif_string(Exiv2Image*, char*, char*, Exiv2Error**)’:
helper.cpp:118:41: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  118 |         Exiv2::ExifData exifData = img->image->exifData();
      |                                         ^~~~~
helper.cpp:122:31: error: ‘AutoPtr’ is not a member of ‘Exiv2::Value’
  122 |                 Exiv2::Value::AutoPtr valueObject = Exiv2::Value::create(Exiv2::asciiString);
      |                               ^~~~~~~
helper.cpp:123:17: error: ‘valueObject’ was not declared in this scope
  123 |                 valueObject->read(value);
      |                 ^~~~~~~~~~~
helper.cpp:126:22: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  126 |                 img->image->setExifData(exifData);
      |                      ^~~~~
helper.cpp:127:22: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  127 |                 img->image->writeMetadata();
      |                      ^~~~~
helper.cpp: In function ‘void exiv2_image_set_exif_short(Exiv2Image*, char*, char*, Exiv2Error**)’:
helper.cpp:138:41: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  138 |         Exiv2::ExifData exifData = img->image->exifData();
      |                                         ^~~~~
helper.cpp:142:31: error: ‘AutoPtr’ is not a member of ‘Exiv2::Value’
  142 |                 Exiv2::Value::AutoPtr valueObject = Exiv2::Value::create(Exiv2::unsignedShort);
      |                               ^~~~~~~
helper.cpp:143:17: error: ‘valueObject’ was not declared in this scope
  143 |                 valueObject->read(value);
      |                 ^~~~~~~~~~~
helper.cpp:146:22: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  146 |                 img->image->setExifData(exifData);
      |                      ^~~~~
helper.cpp:147:22: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  147 |                 img->image->writeMetadata();
      |                      ^~~~~
helper.cpp: In function ‘void exiv2_image_set_iptc_string(Exiv2Image*, char*, char*, Exiv2Error**)’:
helper.cpp:158:41: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  158 |         Exiv2::IptcData iptcData = img->image->iptcData();
      |                                         ^~~~~
helper.cpp:165:22: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  165 |                 img->image->setIptcData(iptcData);
      |                      ^~~~~
helper.cpp:166:22: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  166 |                 img->image->writeMetadata();
      |                      ^~~~~
helper.cpp: In function ‘void exiv2_image_set_iptc_short(Exiv2Image*, char*, char*, Exiv2Error**)’:
helper.cpp:177:37: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  177 |     Exiv2::IptcData iptcData = img->image->iptcData();
      |                                     ^~~~~
helper.cpp:181:23: error: ‘AutoPtr’ is not a member of ‘Exiv2::Value’
  181 |         Exiv2::Value::AutoPtr valueObject = Exiv2::Value::create(Exiv2::unsignedShort);
      |                       ^~~~~~~
helper.cpp:182:9: error: ‘valueObject’ was not declared in this scope
  182 |         valueObject->read(value);
      |         ^~~~~~~~~~~
helper.cpp:185:14: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  185 |         img->image->setIptcData(iptcData);
      |              ^~~~~
helper.cpp:186:14: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  186 |         img->image->writeMetadata();
      |              ^~~~~
helper.cpp: In function ‘long int exiv_image_get_size(Exiv2Image*)’:
helper.cpp:197:23: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  197 |     return (long)img->image->io().size();
      |                       ^~~~~
helper.cpp: In function ‘unsigned char* exiv_image_get_bytes_ptr(Exiv2Image*)’:
helper.cpp:203:17: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  203 |     return img->image->io().mmap();
      |                 ^~~~~
helper.cpp: In function ‘int exiv2_image_get_pixel_width(Exiv2Image*)’:
helper.cpp:210:21: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  210 |         return img->image->pixelWidth();
      |                     ^~~~~
helper.cpp: In function ‘int exiv2_image_get_pixel_height(Exiv2Image*)’:
helper.cpp:214:21: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  214 |         return img->image->pixelHeight();
      |                     ^~~~~
helper.cpp: In function ‘const unsigned char* exiv2_image_icc_profile(Exiv2Image*)’:
helper.cpp:219:18: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  219 |         if (img->image->iccProfileDefined()) {
      |                  ^~~~~
helper.cpp:220:29: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  220 |                 return img->image->iccProfile()->pData_;
      |                             ^~~~~
helper.cpp: In function ‘long int exiv2_image_icc_profile_size(Exiv2Image*)’:
helper.cpp:227:18: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  227 |         if (img->image->iccProfileDefined()) {
      |                  ^~~~~
helper.cpp:228:29: error: ‘Exiv2Image’ {aka ‘struct _Exiv2Image’} has no member named ‘image’
  228 |                 return img->image->iccProfile()->size_;
      |                             ^~~~~
helper.cpp: In function ‘Exiv2XmpData* exiv2_image_get_xmp_data(const Exiv2Image*)’:
helper.cpp:237:38: error: ‘const Exiv2Image’ {aka ‘const struct _Exiv2Image’} has no member named ‘image’
  237 |         return new Exiv2XmpData(img->image->xmpData());
      |                                      ^~~~~
helper.cpp: In function ‘Exiv2IptcData* exiv2_image_get_iptc_data(const Exiv2Image*)’:
helper.cpp:284:39: error: ‘const Exiv2Image’ {aka ‘const struct _Exiv2Image’} has no member named ‘image’
  284 |         return new Exiv2IptcData(img->image->iptcData());
      |                                       ^~~~~
helper.cpp: In function ‘Exiv2ExifData* exiv2_image_get_exif_data(const Exiv2Image*)’:
helper.cpp:354:39: error: ‘const Exiv2Image’ {aka ‘const struct _Exiv2Image’} has no member named ‘image’
  354 |         return new Exiv2ExifData(img->image->exifData());
      |                                       ^~~~~

Please let me know if you have any suggestions or guidance on how to approach this issue, and if there are any additional details needed.

Thank you!

Iptc read data missing

When I read a jpg file and get it iptc metadata with the key "Iptc.Application2.Keywords"
It should be a stringlist or at least "a,b,c...,y,z"
but I only get "z"

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.