[LON-CAPA-cvs] cvs: loncom /interface lonaboutme.pm /lonnet/perl lonnet.pm
neumanie
neumanie@source.lon-capa.org
Thu, 05 Feb 2009 14:56:56 -0000
neumanie Thu Feb 5 14:56:56 2009 EDT
Modified files:
/loncom/interface lonaboutme.pm
/loncom/lonnet/perl lonnet.pm
Log:
Add function to resize a exits image when a user view it. Add seperate funtion to resize a Image in lonnet.pm. Change the max size of a image to 400x500.
Index: loncom/interface/lonaboutme.pm
diff -u loncom/interface/lonaboutme.pm:1.90 loncom/interface/lonaboutme.pm:1.91
--- loncom/interface/lonaboutme.pm:1.90 Mon Jan 26 11:10:10 2009
+++ loncom/interface/lonaboutme.pm Thu Feb 5 14:56:49 2009
@@ -1,7 +1,7 @@
# The LearningOnline Network
# "About Me" Personal Information
#
-# $Id: lonaboutme.pm,v 1.90 2009/01/26 11:10:10 bisitz Exp $
+# $Id: lonaboutme.pm,v 1.91 2009/02/05 14:56:49 neumanie Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -86,6 +86,7 @@
use Apache::lonmsgdisplay();
use Apache::lontemplate;
use HTML::Entities();
+use Image::Magick;
sub handler {
my $r = shift;
@@ -284,8 +285,14 @@
if ($syllabus{'uploaded.photourl'}) {
&Apache::lonnet::allowuploaded('/adm/aboutme',
$syllabus{'uploaded.photourl'});
- $image=qq{<img name="userPhoto" src="$syllabus{'uploaded.photourl'}" />};
+
+ #This call is to resize all "about me" images in the LonCapa System. When its done, you can remove this line.
+ &Apache::lonnet::resizeImage(&Apache::lonnet::filelocation('',$syllabus{'uploaded.photourl'}));
+#--End Resize---
+
+ $image=qq{<img name="userPhoto" src="$syllabus{'uploaded.photourl'}" />};
+
if ($target eq 'tex') {
$image=&Apache::lonxml::xmlparse($r,'tex',$image);
}
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.983 loncom/lonnet/perl/lonnet.pm:1.984
--- loncom/lonnet/perl/lonnet.pm:1.983 Fri Jan 2 23:07:49 2009
+++ loncom/lonnet/perl/lonnet.pm Thu Feb 5 14:56:55 2009
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.983 2009/01/02 23:07:49 raeburn Exp $
+# $Id: lonnet.pm,v 1.984 2009/02/05 14:56:55 neumanie Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2029,6 +2029,24 @@
$fname=~s/\.(\d+)(?=\.)/_$1/g;
return $fname;
}
+#This Function check if a Image max 400px width and height 500px. If not then scale the image down
+sub resizeImage {
+ my($img_url) = @_;
+ my $ima = Image::Magick->new;
+ $ima->Read($img_url);
+ if($ima->Get('width') > 400)
+ {
+ my $factor = $ima->Get('width')/400;
+ $ima->Scale( width=>400, height=>$ima->Get('height')/$factor );
+ }
+ if($ima->Get('height') > 500)
+ {
+ my $factor = $ima->Get('height')/500;
+ $ima->Scale( width=>$ima->Get('width')/$factor, height=>500);
+ }
+
+ $ima->Write($img_url);
+}
#Wrapper function for userphotoupload
sub userphotoupload
@@ -2137,6 +2155,7 @@
$thumbwidth,$thumbheight) = @_;
my $path=$docudom.'/'.$docuname.'/';
my $filepath=$perlvar{'lonDocRoot'};
+
my ($fnamepath,$file,$fetchthumb);
$file=$fname;
if ($fname=~m|/|) {
@@ -2151,6 +2170,7 @@
mkdir($filepath,0777);
}
}
+
# Save the file
{
if (!open(FH,'>'.$filepath.'/'.$file)) {
@@ -2166,21 +2186,7 @@
close(FH);
if($upload_photo_form==1)
{
- my $ima = Image::Magick->new;
- $ima->Read($filepath.'/'.$file);
- if($ima->Get('width') > 300)
- {
- my $factor = $ima->Get('width')/300;
- $ima->Scale( width=>300, height=>$ima->Get('height')/$factor );
- }
- if($ima->Get('height') > 400)
- {
- my $factor = $ima->Get('height')/400;
- $ima->Scale( width=>$ima->Get('width')/$factor, height=>400);
- }
-
-
- $ima->Write($filepath.'/'.$file);
+ resizeImage($filepath.'/'.$file);
$upload_photo_form = 0;
}
}
@@ -2204,7 +2210,7 @@
# Notify homeserver to grep it
#
- my $docuhome=&homeserver($docuname,$docudom);
+ my $docuhome=&homeserver($docuname,$docudom);
my $fetchresult= &reply('fetchuserfile:'.$path.$file,$docuhome);
if ($fetchresult eq 'ok') {
if ($fetchthumb) {
@@ -2336,21 +2342,21 @@
}
sub removeuploadedurl {
- my ($url)=@_;
- my (undef,undef,$udom,$uname,$fname)=split('/',$url,5);
+ my ($url)=@_;
+ my (undef,undef,$udom,$uname,$fname)=split('/',$url,5);
return &removeuserfile($uname,$udom,$fname);
}
sub removeuserfile {
my ($docuname,$docudom,$fname)=@_;
- my $home=&homeserver($docuname,$docudom);
+ my $home=&homeserver($docuname,$docudom);
my $result = &reply("removeuserfile:$docudom/$docuname/$fname",$home);
- if ($result eq 'ok') {
+ if ($result eq 'ok') {
if (($fname !~ /\.meta$/) && (&is_portfolio_file($fname))) {
my $metafile = $fname.'.meta';
my $metaresult = &removeuserfile($docuname,$docudom,$metafile);
my $url = "/uploaded/$docudom/$docuname/$fname";
- my ($file,$group) = (&parse_portfolio_url($url))[3,4];
+ my ($file,$group) = (&parse_portfolio_url($url))[3,4];
my $sqlresult =
&update_portfolio_table($docuname,$docudom,$file,
'portfolio_metadata',$group,
@@ -3856,11 +3862,11 @@
foreach my $item (@$storearr) {
$items.=&escape($item).'&';
}
+
$items=~s/\&$//;
if (!$udomain) { $udomain=$env{'user.domain'}; }
if (!$uname) { $uname=$env{'user.name'}; }
my $uhome=&homeserver($uname,$udomain);
-
return &reply("del:$udomain:$uname:$namespace:$items",$uhome);
}