convert_regions.config 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #------------------------------------------------------------------------------
  2. # File: convert_regions.config
  3. #
  4. # Description: User-defined Composite tag definitions to allow conversion of
  5. # face regions between Microsoft Windows Live Photo Gallery (WLPG)
  6. # and Metadata Working Group (MWG) formats
  7. #
  8. # Usage: 1) Convert from MP WLPG regions to MWG regions:
  9. #
  10. # exiftool -config convert_regions.config "-regioninfo<myregion" FILE
  11. #
  12. # 2) Convert from MWG to WLPG regions:
  13. #
  14. # exiftool -config convert_regions.config "-regioninfomp<myregionmp" FILE
  15. #
  16. # Requires: ExifTool version 8.82 or later
  17. #
  18. # Revisions: 2012/12/27 - P. Harvey Created
  19. # 2013/02/20 - PH Don't add ignored MP faces
  20. #
  21. # References: http://www.metadataworkinggroup.org/specs/
  22. #------------------------------------------------------------------------------
  23. %Image::ExifTool::UserDefined = (
  24. 'Image::ExifTool::Composite' => {
  25. # create an MWG RegionInfo structure from a Microsoft RegionInfoMP structure
  26. MyRegion => {
  27. Require => {
  28. 0 => 'RegionInfoMP',
  29. 1 => 'ImageWidth',
  30. 2 => 'ImageHeight',
  31. },
  32. ValueConv => q{
  33. my ($rgn, @newRgns);
  34. foreach $rgn (@{$val[0]{Regions}}) {
  35. # don't add ignored faces
  36. next if $$rgn{PersonDisplayName} eq 'ffffffffffffffff';
  37. my @rect = split /\s*,\s*/, $$rgn{Rectangle};
  38. my %newRgn = (
  39. Area => {
  40. X => $rect[0] + $rect[2]/2,
  41. Y => $rect[1] + $rect[3]/2,
  42. W => $rect[2],
  43. H => $rect[3],
  44. Unit => 'normalized',
  45. },
  46. Name => $$rgn{PersonDisplayName},
  47. Type => 'Face',
  48. );
  49. push @newRgns, \%newRgn;
  50. }
  51. return {
  52. AppliedToDimensions => { W => $val[1], H => $val[2], Unit => 'pixel' },
  53. RegionList => \@newRgns,
  54. };
  55. },
  56. },
  57. # create a Microsoft RegionInfoMP structure from an MWG RegionInfo structure
  58. MyRegionMP => {
  59. Require => 'RegionInfo',
  60. ValueConv => q{
  61. my ($rgn, @newRgns);
  62. foreach $rgn (@{$val[0]{RegionList}}) {
  63. my @rect = @{$$rgn{Area}}{'X','Y','W','H'};
  64. $rect[0] -= $rect[2]/2;
  65. $rect[1] -= $rect[3]/2;
  66. push @newRgns, {
  67. PersonDisplayName => $$rgn{Name},
  68. Rectangle => join(', ', @rect),
  69. };
  70. }
  71. return { Regions => \@newRgns };
  72. },
  73. },
  74. },
  75. );
  76. 1; #end