#! c:/perl/bin/perl
#
# rszim.cgi
#
# Resizing images, display and make a zip file.
# イメージファイルをリサイズして表示、zip作成
#
# 1.001 : 11/2/05 : エラー処理を修正。サーバーに残った古いファイルを自動削除。
# 1.0 : 10/23/05 : Created
#
# $Id: rszim.cgi,v 1.2 2005/11/23 05:44:59 Hideki Kanayama Exp $
use strict;
use CGI qw(:cgi-lib);
use CGI::Carp qw(fatalsToBrowser);
use GD;
use File::Basename;
use File::Copy;
use Archive::Zip;
use Cwd;
my $lastupdatedyear = 2005;
my $version = "1.001";
my $script = basename($0);
my $charset = "Shift_JIS";
my $lang = 1;
###
my $back = "../rszim.html";
my $body_width = 100;
my $title = 'Resize Image';
my $maxline = 10;
my $bgcolor = 'white';
my $imagedir = '.';
my $prefix = 'rszim';
my $zipfile = "$prefix$$.zip";
my $zipdir = cwd();
my $expire = 60;
my $default_pw = 100;
my $default_ph = 100;
my $default_rw = 50;
my $default_rh = 50;
my $default_ar = 50;
###
my $q = CGI->new;
my $cgierror = $q->cgi_error;
&error($cgierror) if ($cgierror);
my %in = $q->Vars;
if ($in{mode} eq 'resize'){
&resize;
} elsif ($in{mode} eq 'makeimage'){
&makeimage;
} elsif ($in{mode} eq 'delete_image'){
&delete_image;
} elsif ($in{mode} eq 'makezip'){
&makezip;
} else {
&idlepage;
}
sub idlepage {
&delete_zip;
&delete_image_auto;
&htmlhead($title);
print "
\n";
print "
";
my $backname = ("戻る","back")[$lang];
print qq($backname\n);
print "
\n";
print (("画像ファイルを入力してください。 サポートされているファイルはjpeg, gif, png, gd, gd2です。","Please enter your image files. The supported files are jpeg, gif, png, gd and gd2.")[$lang]);
print "
\n";
print qq(
\n";
print qq();
print qq(\n);
&htmltail;
}
sub resize {
my $i;
my $target_type = $in{target_type};
if ($target_type ne 'xy_pixel' and
$target_type ne 'xy_ratio' and
$target_type ne 'area_ratio'){
&error((('変換方法を選択してください。','Please select conversion type')[$lang]));
}
&htmlhead($title);
print "
";
print (("保存は画像をクリックして別ウィンドウで保存するか、右クリックでメニューから保存してください。","Please save photo with right click on a image, or simply click the image and do it on a separate window.")[$lang]);
print "
\n";
print (("サーバー上に変換後の画像ファイルが作成されているので個別に消す場合は「このファイルをサーバーから削除する」をクリックしてください。またまとめて全部消す場合はこのページ一番下にある「変換後の全ての画像をサーバ上から削除する」をクリックしてください。変換後のファイル名を覚えていれば後から$script?mode=delete_image&images=filename,filename,...で削除できます。","The converted files are generated in the server. If you want to delete them from the server individually, please click \"Delete this file on the server\". If you want to delete all of them at once, please click \"Delete all converted files from the server\" link. If you remember file names, you can delete the files by $script?mode=delete_image&images=filename,filename,...")[$lang]);
print "
\n";
print (("まとめてアーカイブされた.zipでダウンロードする場合は、画像を削除する前にこのページ一番下の「まとめてzip fileでダウンロードする」をクリックしてください。","If you want to download with a .zip file, please click \"Download as a zip file\" in the bottom of this page before deleting the images.")[$lang]);
print " \n";
&backbutton;
print "
";
my @new_imagefiles;
for ($i=0;$i<$maxline;$i++){
next unless ($in{$i});
my $imagefile = $q->upload($i);
my $cgierror = $q->cgi_error;
&error($cgierror) if (!$imagefile && $cgierror);
my $image = basename($in{$i});
$image =~ s/^.+[\/\\]([^\/\\]+)$/$1/; #just in case
my ($body,$path,$suffix) = fileparse("$image",'\.\w+');
my $im;
my $image_type;
my $target_type = $q->param('target_type');
if ($suffix =~ /\.jpe?g$/i){
$im = GD::Image->newFromJpeg($imagefile);
$image_type = 'jpg';
} elsif ($suffix =~ /\.gif$/i) {
$im = GD::Image->newFromGif($imagefile);
$image_type = 'gif';
} elsif ($suffix =~ /\.png$/i) {
$im = GD::Image->newFromPng($imagefile);
$image_type = 'png';
} elsif ($suffix =~ /\.gd$/i) {
$im = GD::Image->newFromgd($imagefile);
$image_type = 'gd';
} elsif ($suffix =~ /\.gd2$/i) {
$im = GD::Image->newFromgd2($imagefile);
$image_type = 'gd2';
} else {
close($imagefile) if ($imagefile);
print (("