Skip to content

Commit

Permalink
Merge pull request #1 from fu-hsi/v1.3.0
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
fu-hsi authored Mar 10, 2020
2 parents b04256f + 5935b95 commit 08611a0
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 68 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 1.3.0 - 2020-02-09
### Added
- Support photos without Exif (required timestamp in the file name).
Examples of the valid file names:
- IMG_20200209_124658.jpg,
- IMG_20200209_112021_edited.jpg.

## 1.2.0 - 2018-12-31
### Added
- Extract date and time from filename if DateTimeOriginal Exif tag does't exists.
Expand Down
10 changes: 5 additions & 5 deletions Gpx2Pic/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 75 additions & 53 deletions Gpx2Pic/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,41 +79,38 @@ private void FillListView(string picturesFolder)
ListViewItem item = new ListViewItem(Path.GetFileName(f));
FileInfo fi = new FileInfo(f);
item.SubItems.Add((fi.Length / 1024.0 / 1024.0).ToString("N") + " MB").Name = "FileSize";
item.SubItems.Add("").Name = "Model";
item.SubItems.Add("").Name = "Taken";
item.SubItems.Add("").Name = "ImageSize";
item.SubItems.Add("").Name = "LatLong";

using (ExifReader reader = new ExifReader(f))
try
{
bool isValid = true;

if (reader.GetTagValue(ExifTags.Model, out string model))
{
item.SubItems.Add(model.ToString()).Name = "Model";
}
else
using (ExifReader reader = new ExifReader(f))
{
item.SubItems.Add("").Name = "Model";
}

item.SubItems.Add("").Name = "Taken";
if (reader.GetTagValue(ExifTags.DateTimeOriginal, out DateTime datePictureTaken))
{
DateTime newDatePictureTaken = datePictureTaken.AddSeconds((double)numericUpDownTimeOffset.Value);
string text = datePictureTaken.ToString();
if (numericUpDownTimeOffset.Value != 0)
if (reader.GetTagValue(ExifTags.Model, out string model))
{
text += " -> " + newDatePictureTaken.ToLongTimeString();
item.SubItems["Model"].Text = model;
}
item.SubItems["Taken"].Text = text;
item.Tag = FindNearestTrackPoint(newDatePictureTaken);
}
else
{
string[] tokens = fi.Name.Split('_');
if (tokens.Count() >= 3)

if (reader.GetTagValue(ExifTags.DateTimeOriginal, out DateTime datePictureTaken))
{
if (DateTime.TryParseExact(tokens[1] + tokens[2], "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out datePictureTaken))
DateTime newDatePictureTaken = datePictureTaken.AddSeconds((double)numericUpDownTimeOffset.Value);
string text = datePictureTaken.ToString();
if (numericUpDownTimeOffset.Value != 0)
{
DateTime newDatePictureTaken = datePictureTaken.AddSeconds((double)numericUpDownTimeOffset.Value);
string text = datePictureTaken.ToString();
text += " -> " + newDatePictureTaken.ToLongTimeString();
}
item.SubItems["Taken"].Text = text;
item.Tag = FindNearestTrackPoint(newDatePictureTaken);
}
else
{
DateTime? datePictureTaken2 = ExtractTimeFromFileName(fi.Name);
if (datePictureTaken2.HasValue)
{
DateTime newDatePictureTaken = datePictureTaken2.Value.AddSeconds((double)numericUpDownTimeOffset.Value);
string text = datePictureTaken2.ToString();
if (numericUpDownTimeOffset.Value != 0)
{
text += " -> " + newDatePictureTaken.ToLongTimeString();
Expand All @@ -122,39 +119,42 @@ private void FillListView(string picturesFolder)
item.SubItems["Taken"].Tag = newDatePictureTaken;
item.Tag = FindNearestTrackPoint(newDatePictureTaken);
}
else
{
isValid = false;
}
}
else

if (reader.GetTagValue(ExifTags.PixelXDimension, out uint width) && reader.GetTagValue(ExifTags.PixelYDimension, out uint height))
{
isValid = false;
item.SubItems["ImageSize"].Text = string.Format("{0} x {1}", width, height);
}
}

if (reader.GetTagValue(ExifTags.PixelXDimension, out uint width) && reader.GetTagValue(ExifTags.PixelYDimension, out uint height))
{
item.SubItems.Add(string.Format("{0} x {1}", width, height)).Name = "ImageSize";
}
else

if (item.Tag is GpxPoint point)
{
item.SubItems["LatLong"].Text = string.Format(CultureInfo.InvariantCulture, "{0:F6}, {1:F6}", point.Latitude, point.Longitude);
}
}
}
catch(Exception)
{
DateTime? datePictureTaken2 = ExtractTimeFromFileName(fi.Name);
if (datePictureTaken2.HasValue)
{
item.SubItems.Add("").Name = "ImageSize";
}
DateTime newDatePictureTaken = datePictureTaken2.Value.AddSeconds((double)numericUpDownTimeOffset.Value);
string text = datePictureTaken2.ToString();
if (numericUpDownTimeOffset.Value != 0)
{
text += " -> " + newDatePictureTaken.ToLongTimeString();
}
item.SubItems["Taken"].Text = text;
item.SubItems["Taken"].Tag = newDatePictureTaken;
item.Tag = FindNearestTrackPoint(newDatePictureTaken);

if (item.Tag is GpxPoint point)
{
item.SubItems.Add(string.Format(CultureInfo.InvariantCulture, "{0:F6}, {1:F6}", point.Latitude, point.Longitude)).Name = "LatLong";
}
else
{
item.SubItems.Add("").Name = "LatLong";
isValid = false;
if (item.Tag is GpxPoint point)
{
item.SubItems["LatLong"].Text = string.Format(CultureInfo.InvariantCulture, "{0:F6}, {1:F6}", point.Latitude, point.Longitude);
}
}

item.Checked = isValid;
}

item.Checked = item.Tag != null;
listView1.Items.Add(item);
}

Expand All @@ -168,6 +168,7 @@ private void FillListView(string picturesFolder)

private void Form1_Load(object sender, EventArgs e)
{
listView1_Resize(listView1, EventArgs.Empty);
Text = string.Format("{0} - Automatically geotag your photos (v{1})", Application.ProductName, Application.ProductVersion.Substring(0, Application.ProductVersion.Length - 2));
Analyze();
}
Expand Down Expand Up @@ -486,5 +487,26 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.Save();
}

private DateTime? ExtractTimeFromFileName(string fileName)
{
string[] tokens = Path.GetFileNameWithoutExtension(fileName).Split('_');
if (tokens.Count() >= 3)
{
try
{
if (DateTime.TryParseExact(tokens[1] + tokens[2], "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime datePictureTaken))
{
return datePictureTaken;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

}
return null;
}
}
}
5 changes: 4 additions & 1 deletion Gpx2Pic/Gpx2Pic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -23,7 +24,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
Expand All @@ -46,6 +46,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignManifests>false</SignManifests>
</PropertyGroup>
<ItemGroup>
<Reference Include="ExifLib, Version=1.7.0.0, Culture=neutral, PublicKeyToken=30284005913968db, processorArchitecture=MSIL">
<HintPath>..\packages\ExifLib.1.7.0.0\lib\net45\ExifLib.dll</HintPath>
Expand Down
6 changes: 3 additions & 3 deletions Gpx2Pic/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Gpx2Pic")]
[assembly: AssemblyCopyright("Copyright © 2018 Mariusz Kacki")]
[assembly: AssemblyCopyright("Copyright © 2018-2020 Mariusz Kacki")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ Automatically geotag your photos.
![Screenshot](Screenshots/P1060403.PNG)

## How it works?
1. Select your GPX file, eg. from Strava or Wahoo Fitness and choice folder with photos.
2. Click Analyze button for preview.
3. The program will find nearest track point by timestamp (we take into account your local time zone and the maximum error margin of 5 minutes).
4. Click Save EXIF to update EXIF data in your photos.
1. Select your GPX file, eg. from Strava or Wahoo Fitness and select folder with photos.
2. Click the Save EXIF to update EXIF data.

The program will find nearest track point by timestamp.

## Dependencies
We use some dependencies, which are not imported to repository (from NuGet and external sites):
- ExifTool by Phil Harvey,
- ExifLib by Simon McKenzie,
- Windows API Code Pack by rpastric.
- Windows API Code Pack by rpastric,
- GPX by dlg.krakow.pl,
- Dynamically Sizing Columns by Nick Olsen.

If you are a beginner, just download executable files from releases tab.

## Summary
This project was made for private use in 3 days, so please be understanding.
This project was made for private use in 3 days (excluding later updates), so please be understanding.
Binary file modified Screenshots/Gpx2Pic.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 08611a0

Please sign in to comment.