<s> try : <EOL> import Image <EOL> import ExifTags <EOL> except ImportError : <EOL> try : <EOL> from PIL import Image <EOL> from PIL import ExifTags <EOL> except ImportError : <EOL> raise ImportError ( "<STR_LIT>" ) <EOL> from image_filer . utils import pexif <EOL> def get_exif ( im ) : <EOL> try : <EOL> exif_raw = im . _getexif ( ) or { } <EOL> except : <EOL> return { } <EOL> ret = { } <EOL> for tag , value in exif_raw . items ( ) : <EOL> decoded = ExifTags . TAGS . get ( tag , tag ) <EOL> ret [ decoded ] = value <EOL> return ret <EOL> def get_exif_for_file ( file ) : <EOL> im = Image . open ( file , '<STR_LIT:r>' ) <EOL> return get_exif ( im ) <EOL> def get_subject_location ( exif_data ) : <EOL> try : <EOL> r = ( int ( exif_data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) , int ( exif_data [ '<STR_LIT>' ] [ <NUM_LIT:1> ] ) , ) <EOL> except : <EOL> r = None <EOL> return r <EOL> import StringIO <EOL> def set_exif_subject_location ( xy , fd_source , out_path ) : <EOL> try : <EOL> img = pexif . JpegFile . fromFd ( fd_source ) <EOL> except pexif . JpegFile . InvalidFile , e : <EOL> im = Image . open ( fd_source ) <EOL> new_file_without_exif = StringIO . StringIO ( ) <EOL> im . save ( new_file_without_exif , format = "<STR_LIT>" ) <EOL> img = pexif . JpegFile . fromString ( new_file_without_exif . getvalue ( ) ) <EOL> new_file_without_exif . close ( ) <EOL> img . exif . primary . ExtendedEXIF . SubjectLocation = xy <EOL> img . writeFile ( out_path ) </s>
