@Nullable
    public static Uri getLocalImageFileUriForSharing(final Context context, final Uri imgUri, final String geocode) {

        if (imgUri == null) {
            return null;
        }

        final String storeCode = StringUtils.isBlank(geocode) ? "shared" : geocode;

        Uri imageUri = imgUri;

        if (!UriUtils.isFileUri(imgUri)) {
            //try to find local file in cache image storage
            final File file = LocalStorage.getGeocacheDataFile(storeCode, imgUri.toString(), true, true);
            if (file.exists()) {
                imageUri = Uri.fromFile(file);
            }
        }

        File file = UriUtils.isFileUri(imageUri) ? UriUtils.toFile(imageUri) : null;
        if (file == null || !file.exists()) {
            file = compressImageToFile(imageUri);
        }
        if (file == null) {
            return null;
        }
        file.deleteOnExit();
        final String authority = context.getString(R.string.file_provider_authority);
        return FileProvider.getUriForFile(context, authority, file);

    }
gets or creates local file and shareable Uri for given image. Returns null if creation fails
main/src/main/java/cgeo/geocaching/utils/ImageUtils.java