1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#!/usr/bin/env python
# Lazygal, a static web gallery generator.
# Copyright (C) 2011 Alexandre Rossi <alexandre.rossi@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from gi.repository import GExiv2
def copy_metadata(src, dst):
source_image = GExiv2.Metadata(src)
dest_image = GExiv2.Metadata(dst)
# Save dimensions
if 'Exif.Photo.PixelXDimension' in dest_image \
and 'Exif.Photo.PixelYDimension' in dest_image:
dst_width = dest_image["Exif.Photo.PixelXDimension"]
dst_height = dest_image["Exif.Photo.PixelYDimension"]
has_dims = True
else:
has_dims = False
for tag in source_image.get_exif_tags():
dest_image[tag] = source_image[tag]
for tag in source_image.get_iptc_tags():
dest_image[tag] = source_image[tag]
for tag in source_image.get_xmp_tags():
dest_image[tag] = source_image[tag]
if has_dims:
# set EXIF image size info to resized size
dest_image["Exif.Photo.PixelXDimension"] = dst_width
dest_image["Exif.Photo.PixelYDimension"] = dst_height
dest_image.save_file()
if __name__ == "__main__":
copy_metadata(sys.argv[1], sys.argv[2])
# vim: ts=4 sw=4 expandtab
|