Yoshihisa Fukuhara
higef****@users*****
2006年 2月 23日 (木) 22:36:03 JST
Index: affelio/apps/diary/Diary.pm
diff -u affelio/apps/diary/Diary.pm:1.33 affelio/apps/diary/Diary.pm:1.34
--- affelio/apps/diary/Diary.pm:1.33 Thu Feb 23 21:41:36 2006
+++ affelio/apps/diary/Diary.pm Thu Feb 23 22:36:03 2006
@@ -29,6 +29,7 @@
use HTTP::Request::Common qw(POST);
use AffelioApp;
use HTML::Template;
+use Image::Magick;
##############################################
# Constructor for diary
@@ -749,7 +750,7 @@
}
while ($bytesread = read($filehandle, $buf, 1024)) {
$file .= $buf;
- $self->errorExit('Uploaded file was too big') if (++$filesize >= 300);
+# $self->errorExit('Uploaded file was too big') if (++$filesize >= 300);
}
my $imgdir = "$self->{datadir}img/";
unless (-d $imgdir) {
@@ -759,13 +760,26 @@
unless (-d $basedir) {
mkdir $basedir;
}
+ my $thumbdir = $basedir."thumb/";
+ unless (-d $thumbdir) {
+ mkdir $thumbdir;
+ }
my $distfile = $basedir.$basename;
+ my $thumbfile = $thumbdir.$basename;
# Save file
local (*OUT);
open(OUT, "> $distfile") or $self->errorExit('Failed to open file');
binmode OUT;
print OUT $file;
close(OUT);
+
+# (eval 'use Image::Magick; 1;' ) ? ( $tmpl->param(IMAGEMAGICK => 0) ) : ( $tmpl->param(IMAGEMAGICK =>1) );
+ my $image = Image::Magick->new;
+ $image->Read( $distfile );
+ $image->Resize( geometry=>"300x300" );
+ $image->Set( quality=>75 );
+ $image->Write( $thumbfile );
+
}else{
$self->errorExit('You can only use ascii character in your file name');
}
@@ -807,14 +821,21 @@
$height = "&h=$height" if ($height);
my $imgdir = "$self->{datadir}img/$id/";
+ my $thumbdir = "$self->{datadir}img/$id/thumb/";
my $ret;
+ my $size;
local (*DIR);
opendir(DIR, $imgdir);
while (my $file = readdir(DIR)) {
if (-f $imgdir.$file) {
- $ret .= "<a href=\"show_image.cgi?id=$id&filename=$file\" target=\"_blank\">".
- "<img src=\"show_image.cgi?id=$id&filename=$file$width$height\" border=\"0\" />".
+ if (-f $thumbdir.$file){
+ $size="s";
+ }else{
+ $size="l";
+ }
+ $ret .= "<a href=\"show_image.cgi?id=$id&filename=$file&size=l\" target=\"_blank\">".
+ "<img src=\"show_image.cgi?id=$id&filename=$file$width$height&size=$size\" border=\"0\" />".
"</a><br />";
}
}
Index: affelio/apps/diary/show_image.cgi
diff -u affelio/apps/diary/show_image.cgi:1.7 affelio/apps/diary/show_image.cgi:1.8
--- affelio/apps/diary/show_image.cgi:1.7 Tue Nov 8 13:18:23 2005
+++ affelio/apps/diary/show_image.cgi Thu Feb 23 22:36:03 2006
@@ -26,13 +26,18 @@
$type =~ s/[^.]+\.(.*)/$1/i;
$type =~ s/jpg/jpeg/i;
my $filepath = "$diary->{datadir}img/$id/".$filename;
+my $thumbpath = "$diary->{datadir}img/$id/thumb/".$filename;
my $width = $afap->{cgi}->param('w');
my $height = $afap->{cgi}->param('h');
+my $size = $afap->{cgi}->param('size');
binmode STDOUT;
print "Content-type: image/$type\n\n";
-if ($width and $height and (eval 'use Image::Magick; 1;')) {
+if ($size eq "s"){
+ &output_img($thumbpath);
+}
+elsif ($width and $height and (eval 'use Image::Magick; 1;')) {
try {
my $image = new Image::Magick;
$image->Read(filename => $filepath);