Hi, Ron & Rick
Thanks for the answer, and the whole pl script as below,(it is a little
long but not very complicate)
#!/usr/local/perl/bin/perl
use strict;
use warnings; #those two lines were new added
use Image::Magick;
use Image::Size;
my $option = shift @ARGV; # -r(リサイズ) -d(データ取得) -a(自動判別リサイズ) -rw(横幅リサイズ)
-rh(縦幅リサイズ)
my $file = shift @ARGV; # ファイル名(ディレクトリ付き)
my $elementtype = shift @ARGV; # ロゴかどうか 0:ロゴじゃない 1:ロゴです
my $width = shift @ARGV; # 横幅
my $height = shift @ARGV; # 縦幅
# パラメータチェック
if( $file eq "" || ($option eq "-a" && $elementtype eq "")
|| ($option ne "-a" && $option ne "-r" && $option ne "-d" && $option ne "-rw"
&& $option ne "-rh")
){
print "invalid_argv_err";
exit();
}
my ($x, $y, $size, $type) = &analyze_image_size($file);
if($option eq "-a" && $elementtype eq "1"){
my $image_rate = $y / $x * 100;
if ($image_rate > 25) {
print "image_rate_err";
exit();
}
}
# オプション -a -r の場合は、ステータスを返す
# オプション -d の場合は、画像情報を返す
if($option eq "-a"){
my $status = "stable_ok";
my $resizeflg = "false";
while($size >= 500000){
$resizeflg = "true";
$x = $x * 0.9;
$y = $y * 0.9;
# この比率は、既存Javaプログラム内にあったものを引継
$size = $size * 0.81481428451;
}
if( $resizeflg eq "true"){
my $new_width = int($x);
my $new_height = int($y);
# resize_ok かresize_errを返す
$status = &image_resize($file, $new_width, $new_height);
# ($x, $y, $size, $type) = &analyze_image_size($file);
# print "new_width=>$new_width, new_height=>$new_height,
size=>$size\n";
}
print "$status";
} elsif($option eq "-r") {
# 横縦指定リサイズ
my $width = int($width);
my $height = int($height);
$status = &image_resize($file, $width, $height);
print "$status";
} elsif($option eq "-rw") {
# 横幅リサイズ
my $width = int($width);
$status = &image_resize_width($file, $width);
print "$status";
} elsif($option eq "-rh") {
# 縦幅リサイズ
my $height = int($height);
$status = &image_resize_height($file, $height);
print "$status";
} elsif($option eq "-d") {
print "$x,$y,$size,$type";
}
exit();
#print "analyze_image_size\n";
#print "x->$x , y->$y , size->$size, type->$type\n\n";
# 画像を分析して縦横の長さを返す
# INPUT :ファイル名
# OUTPUT:横の大きさ、縦の大きさ、ファイルサイズ、ファイルタイプ
sub analyze_image_size {
my ( $file ) = @_;
my $filesize = -s $file;
my ( $globe_x, $globe_y, $globe_type ) = imgsize($file);
return ($globe_x, $globe_y, $filesize, $globe_type);
}
# 画像をリサイズ(ファイル名は残さない)
# INPUT :ファイル名、横の大きさ、縦の大きさ
# OUTPUT:実行結果(resize_ok/リサイズ失敗critical_err)
sub image_resize {
my ( $file, $globe_x, $globe_y ) = @_;
my ( $status ) = "resize_ok";
my $i = Image::Magick->new;
$i->Read($file);
# Scaleは縦横のピクセルを与え縮小拡大する
$geometry = "geometry";
$i->Scale(geometry=>$geometry, width=>$globe_x, height=>$globe_y);
# print "Content-type: image/gif\n\n";
# binmode(STDOUT);
# JPEGで出力の場合はjpeg
# $i->Write("gif:-");
$i->Write($file);
if( $! ){ $status = "resize_err" }
return $status ;
}
# 指定した横幅に画像をリサイズ(ファイル名は残さない)
# INPUT :ファイル名、指定した横の長さ
# OUTPUT:実行結果(resize_ok/リサイズ失敗critical_err)
sub image_resize_width {
my ( $status ) = "resize_ok";
my $i = Image::Magick->new;
$i->Read($file);
#リサイズ処理(横幅のみ指定して、縦幅は元ファイルの縦横比率にあわせてリサイズ。)
$i = $i->Transform(geometry=>$width);
# $i->[x]->Scale($width);
$i->Write($file);
if( $! ){ $status = "resize_err" }
return $status ;
}
# 指定した縦幅に画像をリサイズ(ファイル名は残さない)
# INPUT :ファイル名、指定した縦の長さ
# OUTPUT:実行結果(resize_ok/リサイズ失敗critical_err)
sub image_resize_height {
my ( $status ) = "resize_ok";
#リサイズ処理(縦幅より縦横比率に応じた横幅を算出。算出した横幅でリサイズ。)
#縦幅より比率を保った横幅を算出する。
($x, $y, $size, $type) = &analyze_image_size($file);
$width = ($x*$height)/$y;
$width = int($width);
$status = &image_resize_width($file, $width);
if( $! ){ $status = "resize_err" }
return $status ;
}
And I use the command like below,
perl /dev/config/OEM/perl_module/image_resize.pl -rh
/usr/local/tomcat/webapps/favorite/customer/favtest/pc/image/album/thumbnail_uploadFile_120070428122618.jpg
0 0 105
and got the wrong message below:
Global symbol "$status" requires explicit package name at
/dev/config/OEM/perl_module/image_resize.pl line 63.
Global symbol "$status" requires explicit package name at
/dev/config/OEM/perl_module/image_resize.pl line 65.
Global symbol "$status" requires explicit package name at
/dev/config/OEM/perl_module/image_resize.pl line 71.
Global symbol "$status" requires explicit package name at
/dev/config/OEM/perl_module/image_resize.pl line 73.
Global symbol "$status" requires explicit package name at
/dev/config/OEM/perl_module/image_resize.pl line 78.
Global symbol "$status" requires explicit package name at
/dev/config/OEM/perl_module/image_resize.pl line 80.
Global symbol "$geometry" requires explicit package name at
/dev/config/OEM/perl_module/image_resize.pl line 116.
Global symbol "$geometry" requires explicit package name at
/dev/config/OEM/perl_module/image_resize.pl line 117.
Execution of /dev/config/OEM/perl_module/image_resize.pl aborted due to
compilation errors.
The message was different as before as I add two lines.
As I am new to perl, so I have no idea. Thanks.
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users