Class: Exiv2::Image
- Inherits:
-
Object
- Object
- Exiv2::Image
- Defined in:
- lib/exiv2.rb,
ext/image.cpp
Class Method Summary collapse
-
.load_string(string) ⇒ Object
Load Exiv2::Image from memory string content = File.open(“a.jpg”).read img = Exiv2::Image.load_string(content).
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#clear ⇒ Object
Clear all metadata in image.
-
#comment ⇒ Object
Get comment of image.
-
#comment=(comment) ⇒ Object
Set comment in image.
-
#exif ⇒ Object
Access to exif data of image.
-
#initialize(file) ⇒ Object
constructor
img = Exiv2::Image.new(“IMGP3025.jpg”) => #<Exiv2::Image:0x844bc>.
-
#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”)
> #<Exiv2::Image:0x844bc>
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'ext/image.cpp', line 28
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
Load Exiv2::Image from memory string content = File.open(“a.jpg”).read img = Exiv2::Image.load_string(content)
57 58 59 60 61 62 63 64 65 66 67 |
# File 'ext/image.cpp', line 57
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
10 11 12 13 |
# File 'lib/exiv2.rb', line 10 def [](key) return exif[key] if key[0...4] == "Exif" return iptc[key] if key[0...4] == "Iptc" end |
#[]=(key, value) ⇒ Object
15 16 17 18 19 |
# File 'lib/exiv2.rb', line 15 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
92 93 94 95 96 97 98 99 100 |
# File 'ext/image.cpp', line 92
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
105 106 107 108 109 110 111 112 |
# File 'ext/image.cpp', line 105
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
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'ext/image.cpp', line 117
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
}
|
#exif ⇒ Object
Access to exif data of image
143 144 145 146 147 148 149 150 151 |
# File 'ext/image.cpp', line 143 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
156 157 158 159 160 161 162 163 164 |
# File 'ext/image.cpp', line 156 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
80 81 82 83 84 85 86 87 |
# File 'ext/image.cpp', line 80 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”)
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'ext/image.cpp', line 171
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
191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'ext/image.cpp', line 191
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
}
|