#!/usr/bin/perl # # pictpage.pl (Picture Page) # # Copyright (c) 1999,2000,2001 by Yoshinori ARAI # All rights reserved. # # This software may be freely copied, modified and redistributed # without fee provided that this copyright notice is preserved # intact on all copies and modified copies. # # There is no warrantly or other guarantee of fitness of this software. # It is provided solely "as is". The auther(s) desclaim(s) all # responsibility and liability with respect to this software's usage # or its effect upon harware or computer systems. # 文法 # % perl pictpage.pl filetype [-dir dir_name] [-size size] \ # [-format image_format] [-delete] [-norename] > hoge.html # # 動作概要 # カレントディレクトリ下のfiletype拡張子の画像ファイルから # サムネイル化した画像をカレントディレクトリに出力し、 # 標準出力へそれらを表示するためのhtmlを出力します。 # # 出力されるサムネイルのファイル名は # 元ファイル名_ico.拡張子 となります。(元ファイルは残ります) # # -sizeオプション: # 指定されたサイズにリサイズした画像を作成します。 # デフォルトは64x47です。 # # -dirオプション: # 指定されたディレクトリを作成し、そこへサムネイル画像を出力します。 # デフォルトはカレントディレクトリです。 # # -formatオプション: # 指定された画像フォーマットのサムネイル画像を出力します。 # デフォルトはjpegです。 # # -deleteオプション: # サムネイル画像を出力した後、元ファイルを削除します。 # この場合にはHTMLは出力されません。 # # -norenameオプション: # 出力されるファイル名に _ico. をつけるのを抑止します。 # 画像フォーマットを変えずリサイズのみの場合の動作は保証されません。 # # 使用例 # % perl pictpage.pl jpg -dir icon -size 64x47 -format bmp > index.html # カレントディレクトリの *.jpg ファイルを対象とし、 # 64x47サイズにリサイズしbmpに変換したサムネイル画像を # ./iconディレクトリを作成してそこに出力します。 # # % perl resize.pl bmp -size 64x47 -format jpg -delete -norename # カレントディレクトリの *.bmp ファイルを対象とし、 # 64x47サイズにリサイズしjpgに変換したサムネイル画像を # カレントディレクトリに出力します。元画像ファイルは削除されます。 ### プログラム開始 $ver = "1.2"; # Version ### ### 出力されるhtmlに使用されるデフォルト値の設定(適宜変えて下さい) ### $dest_dir = "."; # サムネイル出力先 $isize = "64x47"; # サムネイル画像サイズ $tform = "jpg"; # サムネイル画像種別 $delete = ""; # オリジナルは削除しない $norename = ""; #オリジナルはリネームしない $author = "Yoshinori ARAI"; # 作者名(英語) $author_j = "あらいよしのり"; # 作者名(日本語) $author_mail = 'yoshi@kyo-ko.org'; #作者メールアドレス ### ### パラメータがなければ使用法の表示 ### if(@ARGV=="") { print "pictpage Ver.$ver\n"; print " ex. perl $0 jpg -d icon -s 64x47 -format bmp > hoge.html\n"; print " ソースファイル($0)に詳細が書かれています。\n"; exit; } ### ### filetypeの取り込み (必須オプション) ### $ftype0 = shift; $ftype = "*.$ftype0"; ### ### 他のオプションの取り込み ### while($_=shift) { SWITCH: { if(/-dir/) { $dest_dir = shift; last SWITCH; } if(/-size/) { $isize = shift; last SWITCH; } if(/-format/) { $tform = shift; last SWITCH; } if(/-delete/) { $delete = 1; last SWITCH; } if(/-norename/) { $norename = 1; last SWITCH; } } } # convertコマンドの引数の形に整形する $isize = "-geometry $isize"; ### ### アイコン画像の置き先ディレクトリがカレントでなければ作成 ### (本来はディレクトリが存在したらスキップする処理をいれないといけない) if($dest_dir ne ".") { mkdir("$dest_dir",0777) || die "cannot mkdir $dest_dir"; } while(glob($ftype)) { $orgfile = $_; # ファイル名から拡張子を外す s/.$ftype0//; # ImageMagickのconvertコマンド呼び出し if( $norename eq 1 ) { # リネームしない system ( "convert $isize $orgfile ./$dest_dir/${_}.$tform") && die "cannot convert $_"; } else { # リネームする system ( "convert $isize $orgfile ./$dest_dir/${_}_ico.$tform") && die "cannot convert $_"; } # -deleteオプションが指定されていたら元ファイルを消す if( $delete eq 1 ) { unlink $orgfile; } # rename ("$_", "Photo$n.jpg") || die "cannot rename $_"; } # -deleteオプションが指定されていたらHTMLは出力しない if( $delete eq 1 ) { exit; } ### ### HTML出力 ### # そのままを表示するには print '';で。 print '
'; # 変数を埋め込んで表示するには print "";で。 print "\n"; print "\n"; print ' '; print ""; print '*** ひづけ ***
[HOMEへ]