Skip to content

Commit

Permalink
Merge pull request #150 from LeoHsiao1/dev
Browse files Browse the repository at this point in the history
Ready to release v2.15.0
  • Loading branch information
LeoHsiao1 authored Oct 5, 2024
2 parents cbc6765 + 403ebd2 commit 9744156
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 149 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
python-version: ${{ matrix.python_version }}
- name: Install dependencies
run: |
python -m pip install pyexiv2==2.14.0
python -m pip install pyexiv2==2.15.0
python -m pip install pytest psutil
- name: Test
run: |
Expand All @@ -50,7 +50,7 @@ jobs:
python-version: ${{ matrix.python_version }}
- name: Install dependencies
run: |
python -m pip install pyexiv2==2.14.0
python -m pip install pyexiv2==2.15.0
python -m pip install pytest psutil
- name: Test
run: |
Expand All @@ -77,7 +77,7 @@ jobs:
python-version: ${{ matrix.python_version }}
- name: Install dependencies
run: |
python -m pip install pyexiv2==2.14.0
python -m pip install pyexiv2==2.15.0
python -m pip install pytest psutil
- name: Test
run: |
Expand Down
5 changes: 4 additions & 1 deletion docs/Tutorial-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
class Image:
def __init__(self, filename, encoding='utf-8')
def close(self)

def get_pixel_width (self) -> int
def get_pixel_height(self) -> int
def get_mime_type (self) -> str
def get_access_mode (self) -> dict

Expand Down Expand Up @@ -108,7 +111,7 @@ def convert_iptc_to_xmp(data: dict, encoding='utf-8') -> dict
def convert_xmp_to_exif(data: dict, encoding='utf-8') -> dict
def convert_xmp_to_iptc(data: dict, encoding='utf-8') -> dict

__version__ = '2.14.0'
__version__ = '2.15.0'
__exiv2_version__ = '0.28.3'
```

Expand Down
5 changes: 4 additions & 1 deletion docs/Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Language: [English](./Tutorial.md) | [中文](./Tutorial-cn.md)
class Image:
def __init__(self, filename, encoding='utf-8')
def close(self)

def get_pixel_width (self) -> int
def get_pixel_height(self) -> int
def get_mime_type (self) -> str
def get_access_mode (self) -> dict

Expand Down Expand Up @@ -108,7 +111,7 @@ def convert_iptc_to_xmp(data: dict, encoding='utf-8') -> dict
def convert_xmp_to_exif(data: dict, encoding='utf-8') -> dict
def convert_xmp_to_iptc(data: dict, encoding='utf-8') -> dict

__version__ = '2.14.0'
__version__ = '2.15.0'
__exiv2_version__ = '0.28.3'
```

Expand Down
2 changes: 1 addition & 1 deletion pyexiv2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .core import *


__version__ = '2.14.0'
__version__ = '2.15.0'
__exiv2_version__ = exiv2api.version()


Expand Down
6 changes: 6 additions & 0 deletions pyexiv2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def closed_warning(*args, **kwargs):
else:
setattr(self, attr, None)

def get_pixel_width(self) -> int:
return self._exiv2api_image.get_pixel_width()

def get_pixel_height(self) -> int:
return self._exiv2api_image.get_pixel_height()

def get_mime_type(self) -> str:
""" Get the MIME type of the image, such as 'image/jpeg'. """
return self._exiv2api_image.get_mime_type()
Expand Down
71 changes: 55 additions & 16 deletions pyexiv2/lib/exiv2api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ void logHandler(int level, const char *msg)
switch (level)
{
case Exiv2::LogMsg::debug:
std::cout << "[debug] " << msg << std::endl;
break;
case Exiv2::LogMsg::info:
std::cout << "[info] " << msg << std::endl;
break;
case Exiv2::LogMsg::warn:
std::cout << msg << std::endl;
std::cout << "[warn] " << msg << std::endl;
break;

case Exiv2::LogMsg::error:
// For unknown reasons, the exception thrown here cannot be caught by pybind11, so temporarily save it to error_log.
// throw std::exception(msg);
Expand Down Expand Up @@ -140,6 +143,16 @@ class Image{
return py::bytes((char *)io.mmap(), io.size());
}

py::int_ get_pixel_width()
{
return img->pixelWidth();
}

py::int_ get_pixel_height()
{
return img->pixelHeight();
}

std::string get_mime_type()
{
return img->mimeType();
Expand All @@ -165,7 +178,23 @@ class Image{
py::object read_exif()
{
Exiv2::ExifData &data = img->exifData();
read_block;
py::list result;
for (const auto &datum : data)
{
py::list line;
line.append(py::bytes(datum.key()));
line.append(py::bytes(datum.value().toString()));
if (datum.typeSize() == 0) {
// Don't call py::str(datum.typeName()) on an unknown tag type. Otherwise, it raises a segmentation fault.
// https://github.com/LeoHsiao1/pyexiv2/issues/145
line.append(py::str("unknown"));
} else {
line.append(py::str(datum.typeName()));
}
result.append(line);
}
check_error_log();
return result;
}

py::object read_exif_detail()
Expand All @@ -174,13 +203,20 @@ class Image{
py::list result;
for (const auto &datum : data)
{
py::dict tag_detail = py::dict();
tag_detail["tag"] = py::bytes(datum.key());
tag_detail["idx"] = py::int_(datum.idx());
tag_detail["ifdName"] = py::str(datum.ifdName());
tag_detail["tagDesc"] = py::str(datum.tagDesc());
tag_detail["tagLabel"] = py::str(datum.tagLabel());
tag_detail["typeName"] = py::str(datum.typeName());
py::dict tag_detail = py::dict();
tag_detail["idx"] = py::int_(datum.idx());
tag_detail["ifdName"] = py::str(datum.ifdName());
tag_detail["tag"] = py::bytes(datum.key());
tag_detail["tagDesc"] = py::str(datum.tagDesc());
tag_detail["tagLabel"] = py::str(datum.tagLabel());
tag_detail["tagNumber"] = py::int_(datum.tag());
if (datum.typeSize() == 0) {
// Don't call py::str(datum.typeName()) on an unknown tag type. Otherwise, it raises a segmentation fault.
// https://github.com/LeoHsiao1/pyexiv2/issues/145
tag_detail["typeName"] = py::str("unknown");
} else {
tag_detail["typeName"] = py::str(datum.typeName());
}
tag_detail["value"] = py::bytes(datum.value().toString());
result.append(tag_detail);
}
Expand All @@ -200,12 +236,13 @@ class Image{
py::list result;
for (const auto &datum : data)
{
py::dict tag_detail = py::dict();
tag_detail["tag"] = py::bytes(datum.key());
tag_detail["tagDesc"] = py::str(datum.tagDesc());
tag_detail["tagLabel"] = py::str(datum.tagLabel());
tag_detail["typeName"] = py::str(datum.typeName());
tag_detail["value"] = py::bytes(datum.value().toString());
py::dict tag_detail = py::dict();
tag_detail["tag"] = py::bytes(datum.key());
tag_detail["tagDesc"] = py::str(datum.tagDesc());
tag_detail["tagLabel"] = py::str(datum.tagLabel());
tag_detail["tagNumber"] = py::int_(datum.tag());
tag_detail["typeName"] = py::str(datum.typeName());
tag_detail["value"] = py::bytes(datum.value().toString());
result.append(tag_detail);
}
check_error_log();
Expand Down Expand Up @@ -656,6 +693,8 @@ PYBIND11_MODULE(exiv2api, m)
.def(py::init<Buffer &>())
.def("close_image" , &Image::close_image)
.def("get_bytes" , &Image::get_bytes)
.def("get_pixel_width" , &Image::get_pixel_width)
.def("get_pixel_height" , &Image::get_pixel_height)
.def("get_mime_type" , &Image::get_mime_type)
.def("get_access_mode" , &Image::get_access_mode)
.def("read_exif" , &Image::read_exif)
Expand Down
Loading

0 comments on commit 9744156

Please sign in to comment.