Index: /applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTagger.java
===================================================================
--- /applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTagger.java	(revision 35737)
+++ /applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTagger.java	(revision 35738)
@@ -40,9 +40,10 @@
      * @param ele elevation - can be null if not available
      * @param imgDir image direction in degrees (0..360) - can be null if not available
+     * @param lossy whether to use lossy approach when writing metadata (overwriting unknown tags)
      * @throws IOException in case of I/O error
      */
-    public static void setExifGPSTag(File imageFile, File dst, double lat, double lon, Date gpsTime, Double speed, Double ele, Double imgDir) throws IOException {
+    public static void setExifGPSTag(File imageFile, File dst, double lat, double lon, Date gpsTime, Double speed, Double ele, Double imgDir, boolean lossy) throws IOException {
         try {
-            setExifGPSTagWorker(imageFile, dst, lat, lon, gpsTime, speed, ele, imgDir);
+            setExifGPSTagWorker(imageFile, dst, lat, lon, gpsTime, speed, ele, imgDir, lossy);
         } catch (ImageReadException ire) {
             throw new IOException(tr("Read error: "+ire), ire);
@@ -52,5 +53,5 @@
     }
 
-    public static void setExifGPSTagWorker(File imageFile, File dst, double lat, double lon, Date gpsTime, Double speed, Double ele, Double imgDir)
+    public static void setExifGPSTagWorker(File imageFile, File dst, double lat, double lon, Date gpsTime, Double speed, Double ele, Double imgDir, boolean lossy)
             throws IOException, ImageReadException, ImageWriteException {
 
@@ -148,5 +149,9 @@
         try (BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(dst))) {
             if (metadata instanceof JpegImageMetadata) {
-                new ExifRewriter().updateExifMetadataLossless(imageFile, os, outputSet);
+                if (lossy) {
+                    new ExifRewriter().updateExifMetadataLossy(imageFile, os, outputSet);
+                } else {
+                    new ExifRewriter().updateExifMetadataLossless(imageFile, os, outputSet);
+                }
             } else if (metadata instanceof TiffImageMetadata) {
                 new TiffImageWriterLossy().write(os, outputSet);
Index: /applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/GeotaggingAction.java
===================================================================
--- /applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/GeotaggingAction.java	(revision 35737)
+++ /applications/editors/josm/plugins/photo_geotagging/src/org/openstreetmap/josm/plugins/photo_geotagging/GeotaggingAction.java	(revision 35738)
@@ -35,4 +35,5 @@
 import javax.swing.UIManager;
 
+import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter;
 import org.apache.commons.io.FilenameUtils;
 import org.openstreetmap.josm.gui.ExtendedDialog;
@@ -210,4 +211,5 @@
         private boolean canceled = false;
         private Boolean override_backup = null;
+        private boolean lossy = false;
 
         private File fileFrom;
@@ -258,5 +260,6 @@
             if (canceled) return;
             ExifGPSTagger.setExifGPSTag(fileFrom, fileTo, e.getPos().lat(), e.getPos().lon(),
-                    e.getGpsTime(), e.getSpeed(), e.getElevation(), e.getExifImgDir());
+                    e.getGpsTime(), e.getSpeed(), e.getElevation(), e.getExifImgDir(), lossy);
+            lossy = false;
 
             if (mTime != null) {
@@ -287,8 +290,8 @@
                 } catch (final IOException ioe) {
                     ioe.printStackTrace();
+                    restoreFile();
                     try {
                         SwingUtilities.invokeAndWait(() -> {
                             ExtendedDialog dlg = new ExtendedDialog(progressMonitor.getWindowParent(), tr("Error"), new String[] {tr("Abort"), tr("Retry"), tr("Ignore")});
-                            dlg.setIcon(JOptionPane.ERROR_MESSAGE);
                             dlg.setButtonIcons("cancel", "dialogs/refresh", "dialogs/next");
                             String msg;
@@ -298,9 +301,24 @@
                                 msg = ioe.toString();
                             }
-                            dlg.setContent(tr("Unable to process file ''{0}'':", e.getFile().toString()) + "<br/>" + msg);
+                            boolean tmpLossy = false;
+                            if (!lossy && ioe.getCause() instanceof ExifRewriter.ExifOverflowException) {
+                                tmpLossy = true;
+                                dlg.setIcon(JOptionPane.WARNING_MESSAGE);
+                                dlg.setContent(tr(
+                                        "The GPS tag could not be added to the file \"{0}\" because there is not enough free space in the EXIF section.<br>"
+                                                + "This can likely be fixed by rewriting the entire EXIF section, however some metadata may get lost in the process.<br><br>"
+                                                + "Would you like to try again using the lossy approach?",
+                                        e.getFile().getName()));
+                                dlg.setDefaultButton(2);
+                            } else {
+                                dlg.setIcon(JOptionPane.ERROR_MESSAGE);
+                                dlg.setContent(tr("Unable to process file ''{0}'':", e.getFile().toString()) + "<br/>" + msg);
+                                dlg.setDefaultButton(3);
+                            }
                             dlg.showDialog();
                             switch (dlg.getValue()) {
                                 case 2:  // retry
                                     currentIndex--;
+                                    lossy = tmpLossy;
                                     break;
                                 case 3:  // continue
@@ -417,4 +435,13 @@
         }
 
+        private void restoreFile() {
+            if (fileFrom != null && fileFrom.exists()) {
+                if (fileTo != null && fileTo.exists()) {
+                    fileTo.delete();
+                }
+                fileFrom.renameTo(fileTo);
+            }
+        }
+
         private void cleanupFiles() throws IOException {
             if (fileDelete != null) {
Index: /applications/editors/josm/plugins/photo_geotagging/test/unit/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTaggerTest.java
===================================================================
--- /applications/editors/josm/plugins/photo_geotagging/test/unit/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTaggerTest.java	(revision 35737)
+++ /applications/editors/josm/plugins/photo_geotagging/test/unit/org/openstreetmap/josm/plugins/photo_geotagging/ExifGPSTaggerTest.java	(revision 35738)
@@ -25,8 +25,7 @@
 
     @Test
-    @Ignore("To enable after https://issues.apache.org/jira/browse/IMAGING-179 is fixed")
     public void testTicket11757() throws Exception {
         final File in = new File(TestUtils.getTestDataRoot(), "_DSC1234.jpg");
-        ExifGPSTagger.setExifGPSTag(in, tempFolder.newFile(), 12, 34, new Date(), 12.34, Math.E, Math.PI);
+        ExifGPSTagger.setExifGPSTag(in, tempFolder.newFile(), 12, 34, new Date(), 12.34, Math.E, Math.PI, true);
     }
 
@@ -44,5 +43,5 @@
         final File in = new File(TestUtils.getTestDataRoot(), "IMG_7250_small.JPG");
         final File out = tempFolder.newFile();
-        ExifGPSTagger.setExifGPSTag(in, out, 12, 34, new Date(), 12.34, Math.E, Math.PI);
+        ExifGPSTagger.setExifGPSTag(in, out, 12, 34, new Date(), 12.34, Math.E, Math.PI, false);
         final Process jhead = Runtime.getRuntime().exec(new String[]{"jhead", out.getAbsolutePath()});
         final String stdout = new Scanner(jhead.getErrorStream()).useDelimiter("\\A").next();
