2008-02-11

c3.解像度変換-完成

これで、ほぼ完成のようです。試験でも実働でも問題なかった。
プログラムもスッキリ。そして、分かりやすくなった。

30枚以上の写真を撮って、r101を名変し、数枚を上位に名変して
HTML をちょっと書換えてから、サーバにアップロード。
1時間ほどで出来てしまった。これからは、余分なことしなくていいから楽できそう。

できあがったページは、 http://www.masou.net/room/room.html
プログラムは、メインが photoconv.rb、メソッド定義が conv1.rb、convx.rb 。
実行は、$ ruby photoconv.rb

ファイル名: photoconv.rb ------------------------------------------------
以下、プログラム(インデントは全角スペースなので、copyしてもエラーが出ます)

#! ruby -Ku

# 手作業-1. copy  camera -> original/, temp/
# 手作業-2. rename temp/500x375用 -> r101.jpg

require "conv1"
require "convx"

ipath = "temp"
opath = "converted"

conv1("r101", "500x375", ipath, opath)
convx("r1", "248x186", ipath, opath, 2, 12)
convx("r2", "122x92", ipath, opath, 1, 18)

ファイル名: convx.rb ----------------------------------------------------
#! ruby -Ku

def convx(name_h, pixel, ipath, opath, first, last)
 Dir.open(ipath){|dir|
  count = first
  dir.sort.each{|file|
   if File.extname(file) =~ /\.(JPG|jpg)/
    ifile = ipath + "/" + file
    ofile = opath + "/" + name_h + format("%02d", count) + ".jpg"
    system("convert -geometry " + pixel + " " + ifile + " " + ofile)
    File.delete(ifile)
    count += 1
   end
   break if count > last
  }
 }
end

ファイル名: conv1.rb ------------------------------------------------
#! ruby -Ku

def conv1(name_h, pixel, ipath, opath)
 upper = ipath + "/" + name_h + ".JPG"
 ifile = ipath + "/" + name_h + ".jpg"
 ofile = opath + "/" + name_h + ".jpg"

 File.rename(upper, ifile) if File.exist?(upper)
 if File.exist?(ifile)
  system("convert -geometry " + pixel + " " + ifile + " " + ofile)
  File.delete(ifile)
 else
  puts "r101.jpg が有りません。中止します。"
  exit
 end
end

0 件のコメント: