# Copyright (C) 2003-2005 Kouichirou Eto, All rights reserved.

$LOAD_PATH << "../../lib" unless $LOAD_PATH.include?("../../lib")

module Qwik
  class Action
    # ============================== thumb
    CONVERT_PATH = "/usr/bin/convert"
    THUMB_SIZE = 50

    def thumb_generate(f)
      org_file = @site.attach.path(f)
      attach_dir = @site.attach.path("")
      thumb_dir = attach_dir+".thumb"
      thumb_dir.check_directory
      thumb = thumb_dir+f

      if ! thumb.exist?
	convert = CONVERT_PATH
	return nil if ! convert.path.exist?
	s = THUMB_SIZE
	geom = "#{s}x#{s}"
	cmd = "#{convert} -size #{geom} #{org_file.to_s} #{thumb.to_s}"
#	qp cmd
	system cmd
      end

      return ".attach/.thumb/"+f.to_s
    end
  end
end

if $0 == __FILE__
  require "t/test"
  $debug = true
end

if $debug
  class TC_ActThumbnail < Test::Unit::TestCase
    include TestSession

    def test_all
    end
  end
end
