Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ jobs:

- uses: actions/checkout@v4

- name: Install dependencies
shell: pwsh
run: |
if ($IsWindows) {
choco install exiv2 -y
} elseif ($IsMacOS) {
brew update
brew install exiv2
} else {
sudo apt update
sudo apt install -y libexiv2-dev
}

- name: Install Qt
uses: jurplel/install-qt-action@v4
with:
Expand Down
55 changes: 55 additions & 0 deletions src/qvinfodialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <QDateTime>
#include <QMimeDatabase>
#include <QTimer>
#include <exiv2/exiv2.hpp>
#include <QString>

static int getGcd (int a, int b) {
return (b == 0) ? a : getGcd(b, a%b);
Expand Down Expand Up @@ -47,6 +49,55 @@ void QVInfoDialog::setInfo(const QFileInfo &value, const int &value2, const int
updateInfo();
}

QString readExifData(const QString &imagePath) {
try {
auto image = Exiv2::ImageFactory::open(imagePath.toStdString());
if (!image.get()) return "Error opening image.";

image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
if (exifData.empty()) return "No EXIF data found.";

QString exifOutput;

auto getStr = [&](const char* key) -> QString {
auto it = exifData.findKey(Exiv2::ExifKey(key));
return (it != exifData.end()) ? QString::fromStdString(it->toString()) : "N/A";
};

auto getRationalAsFloat = [&](const char* key, int precision = 2) -> QString {
auto it = exifData.findKey(Exiv2::ExifKey(key));
if (it != exifData.end()) {
Exiv2::Rational r = it->toRational();
if (r.second != 0) {
double value = static_cast<double>(r.first) / r.second;
return QString::number(value, 'f', precision);
}
}
return "N/A";
};

exifOutput += "Camera Make: " + getStr("Exif.Image.Make") + "\n";
exifOutput += "Camera Model: " + getStr("Exif.Image.Model") + "\n";
exifOutput += "Software: " + getStr("Exif.Image.Software") + "\n";
exifOutput += "DateTime: " + getStr("Exif.Image.DateTime") + "\n";
exifOutput += "Exposure Time: " + getStr("Exif.Photo.ExposureTime") + "s\n";
exifOutput += "Aperture: F" + getRationalAsFloat("Exif.Photo.FNumber") + "\n";
exifOutput += "ISO Speed: " + getStr("Exif.Photo.ISOSpeedRatings") + "\n";
exifOutput += "DateTime Original: " + getStr("Exif.Photo.DateTimeOriginal") + "\n";
exifOutput += "DateTime Digitized: " + getStr("Exif.Photo.DateTimeDigitized") + "\n";
exifOutput += "Metering Mode: " + getStr("Exif.Photo.MeteringMode") + "\n";
exifOutput += "Light Source: " + getStr("Exif.Photo.LightSource") + "\n";
exifOutput += "Flash: " + getStr("Exif.Photo.Flash") + "\n";
exifOutput += "Focal Length: " + getRationalAsFloat("Exif.Photo.FocalLength") + " mm\n";
exifOutput += "GPS Latitude: " + getStr("Exif.GPSInfo.GPSLatitude") + "\n";
exifOutput += "GPS Longitude: " + getStr("Exif.GPSInfo.GPSLongitude") + "\n";
return exifOutput;
} catch (const Exiv2::Error &e) {
return QString("EXIF Error: ") + e.what();
}
}

void QVInfoDialog::updateInfo()
{
QLocale locale = QLocale::system();
Expand All @@ -55,12 +106,16 @@ void QVInfoDialog::updateInfo()
//this is just math to figure the megapixels and then round it to the tenths place
const double megapixels = static_cast<double>(qRound(((static_cast<double>((width*height))))/1000000 * 10 + 0.5)) / 10 ;

QString exifData = readExifData(selectedFileInfo.absoluteFilePath());

ui->nameLabel->setText(selectedFileInfo.fileName());
ui->typeLabel->setText(mime.name());
ui->locationLabel->setText(selectedFileInfo.path());
ui->sizeLabel->setText(tr("%1 (%2 bytes)").arg(formatBytes(selectedFileInfo.size()), locale.toString(selectedFileInfo.size())));
ui->modifiedLabel->setText(selectedFileInfo.lastModified().toString(locale.dateTimeFormat()));
ui->dimensionsLabel->setText(tr("%1 x %2 (%3 MP)").arg(QString::number(width), QString::number(height), QString::number(megapixels)));
ui->miscLabel->setText(exifData);

int gcd = getGcd(width,height);
if (gcd != 0)
ui->ratioLabel->setText(QString::number(width/gcd) + ":" + QString::number(height/gcd));
Expand Down
Loading