[LON-CAPA-cvs] cvs: loncom /interface lonaboutme.pm /lonnet/perl lonnet.pm

amueller amueller@source.lon-capa.org
Tue, 09 Dec 2008 11:32:03 -0000


amueller		Tue Dec  9 11:32:03 2008 EDT

  Modified files:              
    /loncom/interface	lonaboutme.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Add wrapper function for user photoupload to determine a photoupload in lonnet.pm. This function is used in lonaboutme.pm. Changes in function finishuserfileupload in lonnet.pm to resize a upload Image to max. size 300x400.By Alexander Schulze and Niels Neumann
  
Index: loncom/interface/lonaboutme.pm
diff -u loncom/interface/lonaboutme.pm:1.78 loncom/interface/lonaboutme.pm:1.79
--- loncom/interface/lonaboutme.pm:1.78	Tue Dec  9 10:45:44 2008
+++ loncom/interface/lonaboutme.pm	Tue Dec  9 11:31:56 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # "About Me" Personal Information
 #
-# $Id: lonaboutme.pm,v 1.78 2008/12/09 10:45:44 ehlerst Exp $
+# $Id: lonaboutme.pm,v 1.79 2008/12/09 11:31:56 amueller Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -236,7 +236,7 @@
 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
 	      }
 	      $syllabus{'uploaded.photourl'}=
-                 &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme');
+                 &Apache::lonnet::userphotoupload('uploaddoc','aboutme');
  	  }
           $syllabus{'uploaded.lastmodified'}=time;
           &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
@@ -270,8 +270,7 @@
        if ($syllabus{'uploaded.photourl'}) {
 	   &Apache::lonnet::allowuploaded('/adm/aboutme',
 					  $syllabus{'uploaded.photourl'});
-	   $image=
-               qq{<img name="userPhoto" src="$syllabus{'uploaded.photourl'}" />};
+	   $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.976 loncom/lonnet/perl/lonnet.pm:1.977
--- loncom/lonnet/perl/lonnet.pm:1.976	Mon Dec  8 23:00:47 2008
+++ loncom/lonnet/perl/lonnet.pm	Tue Dec  9 11:32:03 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.976 2008/12/08 23:00:47 raeburn Exp $
+# $Id: lonnet.pm,v 1.977 2008/12/09 11:32:03 amueller Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -73,6 +73,8 @@
 use strict;
 use LWP::UserAgent();
 use HTTP::Date;
+use Image::Magick;
+
 # use Date::Parse;
 use vars qw(%perlvar %spareid %pr %prp $memcache %packagetab $tmpdir
             $_64bit %env %protocol);
@@ -97,6 +99,8 @@
 my $readit;
 my $max_connection_retries = 10;     # Or some such value.
 
+my $upload_photo_form = 0; #Variable to check  when user upload a photo 0=not 1=true
+
 require Exporter;
 
 our @ISA = qw (Exporter);
@@ -2011,6 +2015,14 @@
     return $fname;
 }
 
+#Wrapper function for userphotoupload
+sub userphotoupload
+{
+	my($formname,$subdir) = @_;
+	$upload_photo_form = 1;
+	return &userfileupload($formname,undef,$subdir);
+}
+
 # --------------- Take an uploaded file and put it into the userfiles directory
 # input: $formname - the contents of the file are in $env{"form.$formname"}
 #                    the desired filenam is in $env{"form.$formname.filename"}
@@ -2137,6 +2149,25 @@
 	    return '/adm/notfound.html';
 	}
 	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);
+		$upload_photo_form = 0;
+	}
     }
     if ($parser eq 'parse') {
         my $parse_result = &extract_embedded_items($filepath.'/'.$file,$allfiles,