Wiki source code of Extraction EXIF data from my Images
Version 3.1 by Normann P. Nielsen on 2026/11/15 15:43
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | To add some new stuff to the [[Mos-Eisley Gallery>>Main.atlassian.atlassian-confluence.mos-eisley-gallery]], I decided to extract [[EXIF>>https://en.wikipedia.org/wiki/Exif]] data and use the GPS part. Inspired by this article: [[https://exposingtheinvisible.org/resources/image-digging]] |
| 2 | |||
| 3 | So, I added the exiftool to the Ubuntu server running Confluence, and added 2 code parts to the code: | ||
| 4 | |||
| 5 | |||
| 6 | {{code language="makeThumbs.sh"}} | ||
| 7 | #Extract EXIF data if the file does not exist | ||
| 8 | if [ ! -f $StartDir/$dir/$pic.exif ] | ||
| 9 | then | ||
| 10 | #Extract EXIF data | ||
| 11 | exiftool -c "%.6f" $pic > $pic.exif | ||
| 12 | echo "extracting EXIF data from $pic" | ||
| 13 | fi | ||
| 14 | {{/code}} | ||
| 15 | |||
| 16 | This little piece extracts EXIF to a file placed alongside the image. | ||
| 17 | |||
| 18 | {{success}}I am giving the EXIF files the .exif filename extension, so they are easy to identify and delete.{{/success}} | ||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | {{code language="updatePages.sh"}} | ||
| 26 | # EXIF Support | ||
| 27 | |||
| 28 | if [ -f $MediaRoot/$Dir/$file/$image.exif ] | ||
| 29 | then | ||
| 30 | |||
| 31 | # An EXIF file exists for the Image | ||
| 32 | |||
| 33 | GPSPos=$(cat "$MediaRoot/$Dir/$file/$image.exif" | grep "GPS Position" | sed 's/GPS\ Position//g' | sed 's/://g') | ||
| 34 | Lattitude=$(echo $GPSPos | awk -F "," '{ print $1 }') | ||
| 35 | Longitude=$(echo $GPSPos | awk -F "," '{ print $2 }') | ||
| 36 | |||
| 37 | fi | ||
| 38 | |||
| 39 | |||
| 40 | .... | ||
| 41 | .... | ||
| 42 | |||
| 43 | |||
| 44 | echo "{me-image:path=$Dir/$file2|image=$image|group=$group|thumbsize=$ThumbSize|displaysize=$DisplaySize|lattitude=$Lattitude|longitude=$Longitude}" >> $WikiPageFile | ||
| 45 | |||
| 46 | |||
| 47 | else | ||
| 48 | |||
| 49 | echo "{me-image:path=$Dir/$file2|image=$image|group=$group|thumbsize=$ThumbSize|displaysize=$DisplaySize|lattitude=$Lattitude|longitude=$Longitude}" >> $WikiFile | ||
| 50 | {{/code}} | ||
| 51 | |||
| 52 | This next part extracts the Lattitide and Longitude from the EXIF file, and adds the data to the "me-image" User Macro - the part that renders the image on the Confluence page | ||
| 53 | |||
| 54 | {{success}}For Open Street Maps its actually not nessesary to split Lattitude and Longitude :){{/success}} | ||
| 55 | |||
| 56 | |||
| 57 | |||
| 58 | finally, I needed to add support to the "me-image" User Macro: | ||
| 59 | |||
| 60 | |||
| 61 | {{code}} | ||
| 62 | ## @param lattitude:title=Lattitude|type=string|required=false|desc=Lattitude Geocoordinat | ||
| 63 | ## @param longitude:title=Longitude|type=string|required=false|desc=Longitude Geocoordinat | ||
| 64 | |||
| 65 | |||
| 66 | .... | ||
| 67 | .... | ||
| 68 | |||
| 69 | |||
| 70 | #if (${paramlattitude} != "" && ${paramlongitude} != "" && ${paramlattitude} && ${paramlongitude} ) | ||
| 71 | <br>View photo location on Open Street Map: <a href="https://www.openstreetmap.org/search?query=${paramlattitude},${paramlongitude}&namedetails=1&zoom=18&addressdetails=1" target="_location"><img src="http://www.mos-eisley.dk/download/attachments/28344459/OpenStreetMapIcon.png?api=v2" width=20px></a> | ||
| 72 | #end | ||
| 73 | {{/code}} | ||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | Now, if the Image has GPS coordinates, a small icon will be rederen with a link to Open Street Maps: | ||
| 78 | |||
| 79 | [[image:Screen Shot 2018-01-03 at 20.48.45.png||width="674"||height="223"||alt="Screen Shot 2018-01-03 at 20.48.45.png"]] | ||
| 80 | |||
| 81 | Links to: | ||
| 82 | |||
| 83 | [[image:Screen Shot 2018-01-03 at 20.49.20.png||width="800"||alt="Screen Shot 2018-01-03 at 20.49.20.png"]] |