Class: Exiv2::Image
- Inherits:
-
Object
- Object
- Exiv2::Image
- Defined in:
- ext/image.cpp,
lib/exiv2.rb,
ext/image.cpp
Overview
Class Method Summary collapse
-
.load_string(string) ⇒ Object
Load Exiv2::Image from memory string.
Instance Method Summary collapse
-
#[](key) ⇒ Object
method [] is used to read exif or iptc data.
-
#[]=(key, value) ⇒ Object
method []= is used to set exif or iptc data.
-
#clear ⇒ Object
Clear all metadata in image.
-
#comment ⇒ Object
Get comment of image.
-
#comment=(comment) ⇒ Object
Set comment in image.
-
#created_at ⇒ Object
clues together Iptc.Application2.DateCreated and Iptc.Application2.TimeCreated if possible.
-
#Exif ⇒ Object
Access to exif data of image.
-
#exif ⇒ Object
Access to exif data of image.
-
#initialize(file) ⇒ Object
constructor
img = Exiv2::Image.new(“IMGP3025.jpg”).
-
#iptc ⇒ Object
Access to iptc data of image.
-
#save ⇒ Object
Save image with changed data.
-
#thumbnail(file_name) ⇒ Object
Dump thumbnail to file.
-
#thumbnail=(file_name) ⇒ Object
Set image thumbnail to contents of passed file.
Constructor Details
#initialize(file) ⇒ Object
img = Exiv2::Image.new(“IMGP3025.jpg”)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'ext/image.cpp', line 35
static VALUE exiv2_image_initialize(VALUE self, VALUE file) {
__BEGIN
rbImage* image;
Data_Get_Struct(self, rbImage, image);
try {
if(rb_respond_to(file, rb_intern("read"))) {
VALUE file_content = rb_funcall(file, rb_intern("read"), 0);
rb_iv_set(self, "@file_content", file_content);
image->image = Exiv2::ImageFactory::open(CBSTR(file_content), LEN(file_content));
} else if(TYPE(file) == T_STRING) {
image->image = Exiv2::ImageFactory::open(CSTR(file));
}
image->image->readMetadata();
}
catch(const Exiv2::AnyError&) {
rb_raise(rb_eStandardError, "Cannot open file %s", STR(file));
}
return self;
__END
}
|
Class Method Details
.load_string(string) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'ext/image.cpp', line 65
static VALUE exiv2_image_load_string(VALUE self, VALUE string) {
__BEGIN
Check_Type(string, T_STRING);
rbImage* image = new rbImage();
image->dirty = false;
VALUE img = Data_Wrap_Struct(self, 0, image_delete, image);
image->image = Exiv2::ImageFactory::open(CBSTR(string), LEN(string));
return img;
__END
}
|
Instance Method Details
#[](key) ⇒ Object
method [] is used to read exif or iptc data
15 16 17 18 |
# File 'lib/exiv2.rb', line 15 def [](key) return exif[key] if key[0...4] == "Exif" return iptc[key] if key[0...4] == "Iptc" end |
#[]=(key, value) ⇒ Object
method []= is used to set exif or iptc data
21 22 23 24 25 |
# File 'lib/exiv2.rb', line 21 def []=(key, value) return exif[key] = value if key[0...4] == "Exif" return iptc[key] = value if key[0...4] == "Iptc" raise Exiv2::Error, "Unknown key for writing: #{key.inspect}" end |
#clear ⇒ Object
Clear all metadata in image. Not only exif
100 101 102 103 104 105 106 107 108 |
# File 'ext/image.cpp', line 100
static VALUE exiv2_image_clear(VALUE self) {
__BEGIN
rbImage* image;
Data_Get_Struct(self, rbImage, image);
image->image->clearMetadata();
image->dirty = true;
return self;
__END
}
|
#comment ⇒ Object
Get comment of image
113 114 115 116 117 118 119 120 |
# File 'ext/image.cpp', line 113
static VALUE exiv2_image_get_comment(VALUE self) {
__BEGIN
rbImage* image;
Data_Get_Struct(self, rbImage, image);
std::string comment = image->image->comment();
return rb_str_new(comment.c_str(), comment.length());
__END
}
|
#comment=(comment) ⇒ Object
Set comment in image
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'ext/image.cpp', line 125
static VALUE exiv2_image_set_comment(VALUE self, VALUE comment) {
__BEGIN
rbImage* image;
Data_Get_Struct(self, rbImage, image);
switch(TYPE(comment)) {
case T_STRING: {
image->image->setComment(CSTR(comment));
image->dirty = true;
break;
}
case T_NIL: {
image->image->clearComment();
image->dirty = true;
break;
}
default: {
rb_raise(rb_eStandardError, "Can only set comment to string, or clear it with nil value");
}
}
return comment;
__END
}
|
#created_at ⇒ Object
clues together Iptc.Application2.DateCreated and Iptc.Application2.TimeCreated if possible
28 29 30 31 32 33 |
# File 'lib/exiv2.rb', line 28 def created_at date = iptc["Iptc.Application2.DateCreated"] time = iptc["Iptc.Application2.TimeCreated"] return date unless time Time.utc(date.year, date.month, date.day, time.hour, time.min, time.sec) end |
#Exif ⇒ Object
Access to exif data of image
151 152 153 154 155 156 157 158 159 |
# File 'ext/image.cpp', line 151 static VALUE exiv2_image_exif(VALUE self) { __BEGIN rbImage* image; Data_Get_Struct(self, rbImage, image); VALUE exif = Data_Wrap_Struct(cExif, 0, image_leave, image); rb_iv_set(exif, "@image", self); return exif; __END } |
#exif ⇒ Object
Access to exif data of image
151 152 153 154 155 156 157 158 159 |
# File 'ext/image.cpp', line 151 static VALUE exiv2_image_exif(VALUE self) { __BEGIN rbImage* image; Data_Get_Struct(self, rbImage, image); VALUE exif = Data_Wrap_Struct(cExif, 0, image_leave, image); rb_iv_set(exif, "@image", self); return exif; __END } |
#iptc ⇒ Object
Access to iptc data of image
164 165 166 167 168 169 170 171 172 |
# File 'ext/image.cpp', line 164 static VALUE exiv2_image_iptc(VALUE self) { __BEGIN rbImage* image; Data_Get_Struct(self, rbImage, image); VALUE iptc = Data_Wrap_Struct(cIptc, 0, image_leave, image); rb_iv_set(iptc, "@image", self); return iptc; __END } |
#save ⇒ Object
Save image with changed data
88 89 90 91 92 93 94 95 |
# File 'ext/image.cpp', line 88 static VALUE exiv2_image_save(VALUE self) { __BEGIN rbImage* image; Data_Get_Struct(self, rbImage, image); image_real_save(image); return self; __END } |
#thumbnail(file_name) ⇒ Object
Dump thumbnail to file. @img.thumbnail(“my_image”)
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'ext/image.cpp', line 179
static VALUE exiv2_image_thumbnail(VALUE self, VALUE file_name) {
__BEGIN
Check_Type(file_name, T_STRING);
rbImage* image;
Data_Get_Struct(self, rbImage, image);
Exiv2::ExifData &exifData = image->image->exifData();
exifData.writeThumbnail(STR(file_name));
if(rb_block_given_p()) {
rb_yield(file_name);
}
return self;
__END
}
|
#thumbnail=(file_name) ⇒ Object
Set image thumbnail to contents of passed file
199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'ext/image.cpp', line 199
static VALUE exiv2_image_thumbnail_set(VALUE self, VALUE file_name) {
__BEGIN
Check_Type(file_name, T_STRING);
rbImage* image;
Data_Get_Struct(self, rbImage, image);
Exiv2::ExifData &exifData = image->image->exifData();
exifData.setJpegThumbnail(STR(file_name));
return self;
__END
}
|