MovableTypeでの画像管理
MovableTypeの仕事が多いです。そんな時に、「画像管理の方法は無いの?」と聞かれました。そこで、ちょっと作ってみた。
filelist.cgi
#!/usr/local/bin/perl -w use strict; use IO::File; use lib 'extlib'; use Image::Size; use HTML::Template; use lib 'lib'; use MT; use MT::Blog; #-------------------------------------------------- my $mt = MT->new( Config => "mt-config.cgiの場所"); my $blog_id = 1; my $blog = MT::Blog->load($blog_id) or die "cannnot load blog."; my $dir = $blog->site_path; my $tempfile = './filelist.tmpl'; print "Content-type: text/html\n\n"; opendir DIR, $dir or die "opendir miss : $!"; my @files = readdir DIR; @files = grep ( /(.jpg|.gif|.png)/, @files ); closedir DIR; #print ( map { $_ . "<br>\n" } @files ); my @fl; foreach my $file ( @files ){ my ($x, $y, $id) = imgsize( $file ); my $filetemp = { path => $blog->site_url, name => $file, #横 x => $x, #横 y => $y, #高 #id => lc $id, }; push @fl,$filetemp; } my $template = HTML::Template->new(filename => $tempfile); $template->param( EMPLOYEE_INFO => \@fl ); print $template->output;
filelist.tmpl
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> <title>FileList</title> </head> <body> <h1>FileList</h1> <TMPL_LOOP NAME=EMPLOYEE_INFO> <p><img src="<TMPL_VAR NAME=path><TMPL_VAR NAME=name>" width="<TMPL_VAR NAME=x>" height="<TMPL_VAR NAME=y>" alt=""></p> <textarea> <img src="<TMPL_VAR NAME=path><TMPL_VAR NAME=name>" width="<TMPL_VAR NAME=x>" height="<TMPL_VAR NAME=y>" alt=""> </textarea> </TMPL_LOOP> </body> </html>