Sponsored Link

movabletype plugin GPS Ready をいじってみた。

| コメント(0) | トラックバック(1) |
||

perlの勉強も兼ねてmovabletype exif情報を抽出するプラグインをちょっと改造してみました。

perlの勉強も兼ねて、先日公開されたmovabletypeプラグインGPS Ready(Twitter / apstar作) MT4.2:JPEGファイルのEXIF情報を取得するプラグイン(GPS Ready)をいじってみた。後日、詳しく書き足すつもり。(時間がないので)

<追記>以前からExif情報のプラグインを作ってみたいと考えていたのもあって、実際に自分が欲しい機能を追加できるようにいじくってみた

GPS Readyのサブルーチンを編集。編集内容は、モバイル用の写真データ用のexif情報、デジタルカメラ用のexif情報をoption で選択変更できるようにしたこと。まだまだ、モバイル用とデジカメ用のexif情報の項目をもっと絞る必要がある。あとは、項目が英文で導きだされるのでそれを日本語に変換するためのハッシュを用意し、日本語訳exif情報が出力されるようにするつもりで編集。

exif情報の日本語訳ハッシュもサブルーチンの中に埋め込まず、別テキストから読み込んで、ハッシュを生成させるようにすれば、ちょっとは再帰的なコードが出来上がると考えている。

sub _hdlr_getexif {
my ($ctx, $args) = @_;
my $file = $args->{filepath};
my $option = $args->{option};
my $exif_tool = new Image::ExifTool;

my $exif_info = $exif_tool->ImageInfo( $file, (patt($option)) );

#key日本語訳用のハッシュ
=pod
my %trans = {
	ExposureTime => "露出時間",
	WhiteBalance => "ホワイトバランス",
	Flash => "フラッシュ",
	FileSize => "ファイルサイズ",
		};
=cut

my $out;
        foreach my $key ( sort keys %$exif_info){
#            $out .= "$trans{$key} => $$exif_info{$key}
\n"; $out .= "$key => $$exif_info{$key}
\n"; } return $out; } #$option 分岐サブ sub patt { my $option = shift; my @mobile = qw ( CustomRendered DateTimeOriginal DigitalZoomRatio ExposureMode ExposureTime FileSize FileType Flash ImageSize Make Model ShutterSpeed WhiteBalance GPSPosition GPSProcessingMethod ); my @photo = qw( AFAperture AFAreaMode AFPoint Aperture Contrast CreateDate ExposureDifference ExposureMode ExposureTime FNumber FileSize FileType Flash FocalLength FocusMode HyperfocalDistance ISO ImageSize Lens LensID LightSource Make Model Quality Saturation Sharpness WhiteBalance WhiteBalanceFineTune ); if ( $option eq 'photo' ){ return @photo; } elsif ( $option eq 'mobile' ){ return @mobile; } else { return; } }

以下のテンプレートタグで各写真ごとに出力できる。

<MTAssets lastn="5">
<MTSetVarBlock name="NewestAssetURL"><MTAssetFilePath></MTSetVarBlock>
<img src="<$MTAssetURL$>" />
<MTGetEXIF filepath="$NewestAssetURL" option="[mobile or photo or none]">
</MTAssets>

モジュールExifについてお試し用のコマンド用スクリプトが以下。perl exifall.pl でExif情報がコマンドラインで操作できると。

#!/usr/bin/perl
use strict;
use warnings;
use Image::ExifTool;
use File::Basename;
my $filename = basename(__FILE__);
my $file = $ARGV[0]
    or die "Usage: $filename file\n";
#my $file = "./image.jpg";
my $exif = new Image::ExifTool;
my $info = $exif->ImageInfo($file);

foreach (sort keys %$info) {
  print "$_ => $$info{$_}\n";
  }
print "\n";
print "GetTagList\n";
print "\n";
my @tags = $exif->GetTagList($info, 'Group0');
for (@tags){
        print $_,"\n";
}
print "\n";
print "option\n";
print "\n";
#my %options = (PrintConv => 0);
my $option = "mobile";
my @tagList = qw( filename imagesize );
my $info_tag = $exif->ImageInfo($file, (pat($option)) );
foreach (sort keys %$info_tag){
        print "$_ => $$info_tag{$_}\n";
}
sub pat {
        $option = shift;
        if ( $option eq "mobile" ){
        return @tagList;
        }else{
        return;
        }
}

willcom esで撮影した写真のexif情報
About => uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b
BitsPerSample => 8
ColorComponents => 3
Creatortool => Microsoft Windows Live Photo Gallery12.0.1329.201
Directory => /home/coolniikou/photo
EncodingProcess => Baseline DCT, Huffman coding
ExifByteOrder => Big-endian (Motorola, MM)
ExifToolVersion => 7.60
FileModifyDate => 2008:08:30 01:37:36+09:00
FileName => img697.jpg
FileSize => 762 kB
FileType => JPEG
ImageHeight => 1024
ImageSize => 1280x1024
ImageWidth => 1280
JFIFVersion => 1.01
MIMEType => image/jpeg
ModifyDate => 2008:08:30 01:37:36
Orientation => Horizontal (normal)
Orientation (1) => Horizontal (normal)
ResolutionUnit => inches
Software => Microsoft Windows Live Photo Gallery12.0.1329.201
XResolution => 192
YCbCrSubSampling => YCbCr4:2:0 (2 2)
YResolution => 192
デジタル一眼でのexif情報
AELock => Off
AELockButton => AE/AF Lock
AFAperture => 3.5
AFAreaMode => Dynamic Area, Closest Subject
AFAreaModeSetting => Dynamic Area
AFAssist => On
AFPoint => Center
AFPointsInFocus => Center
Aperture => 5.6
AutoBracketRelease => Auto Release
AutoISO => Off
AutoISOMax => 1600
AutoISOMinShutterSpeed => 1/30 s
Beep => On
BitsPerSample => 8
BlueBalance => 1.363281
CFAPattern => [Green,Blue][Red,Green]
CircleOfConfusion => 0.020 mm
ColorBalance1 => 1.83984375 1.36328125 1 1
ColorComponents => 3
ColorHue => Mode3a
ColorMode => Color
ColorSpace => sRGB
ColorSpace (1) => sRGB
ComponentsConfiguration => YCbCr
CompressedBitsPerPixel => 4
Compression => JPEG (old-style)
Compression (1) => JPEG (old-style)
Contrast => Normal
CreateDate => 2008:09:19 18:01:37
CropHiSpeed => Off (3904x2616 cropped to 3904x2616 at pixel 0,0)
CustomRendered => Normal
DOF => 1.33 m (0.88 - 2.21)
DateTimeOriginal => 2008:09:19 18:01:37
DigitalZoomRatio => 1
Directory => /home/coolniikou/photo
EffectiveMaxAperture => 3.6
EncodingProcess => Baseline DCT, Huffman coding
ExifByteOrder => Big-endian (Motorola, MM)
ExifImageHeight => 2592
ExifImageWidth => 3872
ExifToolVersion => 7.60
ExifVersion => 0221
ExitPupilPosition => 66.1 mm
ExposureCompensation => 0
ExposureDifference => 0
ExposureMode => Auto
ExposureProgram => Not Defined
ExposureTime => 1/125
ExternalFlashFlags => (none)
FNumber => 5.6
FOV => 66.6 deg (1.65 m)
FileModifyDate => 2008:09:19 18:01:37+09:00
FileName => DSC_0010.JPG
FileSize => 3.6 MB
FileSource => Digital Camera
FileType => JPEG
Flash => Off
FlashCommanderMode => Off
FlashControlMode => Off
FlashExposureComp => 0
FlashExposureComp (1) => 0
FlashGroupAControlMode => Off
FlashGroupAExposureComp => 0
FlashGroupBControlMode => Off
FlashGroupBExposureComp => 0
FlashGroupCControlMode => Off
FlashGroupCExposureComp => 0
FlashInfoVersion => 0102
FlashLevel => +0.0
FlashMode => Did Not Fire
FlashModel => (none)
FlashSetting =>
FlashType =>
FlashpixVersion => 0100
FocalLength => 18.0 mm
FocalLength (1) => 18.3 mm
FocalLength35efl => 18.0 mm (35 mm equivalent: 27.0 mm)
FocalLengthIn35mmFormat => 27 mm
FocusDistance => 1.26 m
FocusMode => AF-A
FocusModeSetting => AF-A
FocusPosition => 0x53
GainControl => None
HighISONoiseReduction => Off
HueAdjustment => 0
HyperfocalDistance => 2.89 m
ISO => 200
ISO (1) => 200
ISOSetting => 200
ImageBoundary => 0 0 3872 2592
ImageDataSize => 3675140
ImageHeight => 2592
ImageOptimization =>
ImageReview => On
ImageReviewTime => 4 s
ImageSize => 3872x2592
ImageWidth => 3872
InternalFlash => TTL
InteropIndex => R98 - DCF basic file (sRGB)
InteropVersion => 0100
Lens => 18-55mm f/3.5-5.6
LensDataVersion => 0202
LensFStops => 5.33
LensFStops (1) => 5.33
LensID => AF-S DX Zoom-Nikkor 18-55mm f/3.5-5.6G ED II
LensIDNumber => 148
LensSpec => 18-55mm f/3.5-5.6 G
LensType => G
LightSource => Natural
LightSource (1) => Unknown
LightValue => 10.9
MCUVersion => 150
MIMEType => image/jpeg
Make => NIKON CORPORATION
MakerNoteVersion => 2.10
ManualFlashOutput => Full
MaxApertureAtMaxFocal => 5.7
MaxApertureAtMinFocal => 3.6
MaxApertureValue => 3.5
MaxFocalLength => 55.0 mm
Metering => Matrix
MeteringMode => Multi-segment
MeteringTime => 8 s
MinFocalLength => 18.3 mm
Model => NIKON D40X
ModifyDate => 2008:09:19 18:01:37
MonitorOffTime => 8 s
MultiExposureAutoGain => Off
MultiExposureMode => Off
MultiExposureShots => 0
MultiExposureVersion => 0100
NoMemoryCard => Release Locked
NoiseReduction => Off
Orientation => Horizontal (normal)
PreviewImage => SCALAR(0x85d6648)
PreviewImageLength => 25059
PreviewImageStart => 3676
ProgramShift => 0
Quality => Fine
RedBalance => 1.839844
RemoteOnDuration => 1 min
ResolutionUnit => inches
ResolutionUnit (1) => inches
ResolutionUnit (2) => inches
RetouchHistory => None
Saturation => Normal
Saturation (1) => Auto
ScaleFactor35efl => 1.5
SceneCaptureType => Standard
SceneType => Directly photographed
SelfTimerTime => 10 s
SensingMethod => One-chip color area
SensorPixelSize => 6.05 x 6.05 um
SerialNumber => 2127809
Sharpness => Normal
Sharpness (1) => Auto
ShootingMode => Continuous
ShootingModeSetting => Continuous
ShotInfoVersion => 0209
ShutterCount => 1984
ShutterCount (1) => 1984
ShutterSpeed => 1/125
Software => Ver.1.00
SubSecDateTimeOriginal => 2008:09:19 18:01:37.00
SubSecTime => 00
SubSecTimeDigitized => 00
SubSecTimeOriginal => 00
SubjectDistanceRange => Unknown
ThumbnailImage => SCALAR(0x8691740)
ThumbnailLength => 9276
ThumbnailOffset => 28876
TimerFunctionButton => Self-timer
ToneComp => Auto
UserComment =>
VRInfoVersion => 0100
VariProgram => Auto(Flash Off)
VibrationReduction => Off
VibrationReduction (1) => Off
WB_RGGBLevels => 471 256 256 349
WhiteBalance => Auto
WhiteBalance (1) => Auto
WhiteBalanceFineTune => 0
XResolution => 300
XResolution (1) => 300
XResolution (2) => 300
YCbCrPositioning => Co-sited
YCbCrPositioning (1) => Co-sited
YCbCrPositioning (2) => Co-sited
YCbCrSubSampling => YCbCr4:2:2 (2 1)
YResolution => 300
YResolution (1) => 300
YResolution (2) => 300
やはりデジタル一眼はかなり細かい仕様まで抽出できる。これらのリストからユーザが欲しがる情報を抜き出して、それらをリストにする。

Comments for this entry on FriendFeed.

トラックバック(1)

トラックバックURL: http://weblibrary.s224.xrea.com/x/mt/mt-tb.cgi/2710

MT4.2:JPEGファイルのEXIF情報を取得するプラグイン(GPS Read... 続きを読む

コメントする

サービス

AmaPOP - amazon affiliate link generator/アマゾンアソシエイト(アフィリエイト)リンク

AmaPOP - amazon affiliate link generator
手軽にあなたのアソシエイトID入りのアマゾンアソシエイト(アフィリエイト)リンクを作成することができるサービス

人気アクセスランキング

OpenID対応しています OpenIDについて
Powered by Movable Type 4.25

このブログ記事について

このページは、cool_ni_ikouが2009年2月21日 09:22に書いたブログ記事です。

ひとつ前のブログ記事は「Movabletype4.2x GoogleAJAXFeedAPIを使ってLPO対策 」です。

次のブログ記事は「Movabletypeプラグイン AssetExifリリースのお知らせ」です。

edit

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。