Transfers oldfile's exif to newfile's exif and
    updates the width/height EXIF fields

def update_exif_GEXIV2(oldfile,newfile):
    """Transfers oldfile's exif to newfile's exif and
    updates the width/height EXIF fields"""

    # Requires gexiv2 and pygobject package in gentoo 
    # (USE=introspection)
    try:
        from gi.repository import GExiv2 
    except:
        print("Couldn't import GExiv2")
        print("Are you sure you have GExiv2 installed?")
        print("See this page: http://goo.gl/0bhDGx")
        print("For gentoo, emerge media-libs/gexiv2 with introspection USE flag")
        return False
        


    # exif of orginal image
    exif = GExiv2.Metadata(oldfile)

    # exif of resized image
    newExif = GExiv2.Metadata(newfile)

    # Figure out dimensions
    imgresize = Image.open(newfile)

    # save all exif data of orinal image to resized
    for tag in exif.get_exif_tags():
        newExif[tag] = exif[tag]

    # edit exif data - size 
    newExif['Exif.Photo.PixelXDimension'] = str(imgresize.size[0])
    newExif['Exif.Photo.PixelYDimension'] = str(imgresize.size[1])
    # FIXME: Doesn't work with PENTAX JPG
    # Error is: gi._glib.GError: Unsupported data area offset type
    newExif.save_file()

    return True