--- loncom/interface/domainprefs.pm 2007/05/27 16:31:54 1.15 +++ loncom/interface/domainprefs.pm 2007/05/27 21:21:26 1.16 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.15 2007/05/27 16:31:54 raeburn Exp $ +# $Id: domainprefs.pm,v 1.16 2007/05/27 21:21:26 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -550,6 +550,7 @@ sub display_color_options { $showfile = ''; } } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) { + $showfile = $imgfile; my $imgdir = $1; my $filename = $2; if (-e "/home/httpd/html/$imgdir/tn-".$filename) { @@ -559,12 +560,17 @@ sub display_color_options { my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename; if (!-e $output) { my ($width,$height) = &thumb_dimensions(); - my $size = $width.'x'.$height; - system("convert -sample $size $input $output"); + my ($fullwidth,$fullheight) = &check_dimensions($input); + if ($fullwidth ne '' && $fullheight ne '') { + if ($fullwidth > $width && $fullheight > $height) { + my $size = $width.'x'.$height; + system("convert -sample $size $input $output"); + $showfile = '/'.$imgdir.'/tn-'.$filename; + } + } } - $showfile = '/'.$imgdir.'/tn-'.$filename; } - } + } if ($showfile) { $showfile = &Apache::loncommon::lonhttpdurl($showfile); $fullsize = &Apache::loncommon::lonhttpdurl($imgfile); @@ -1237,6 +1243,26 @@ sub thumb_dimensions { return ('200','50'); } +sub check_dimensions { + my ($inputfile) = @_; + my ($fullwidth,$fullheight); + if ($inputfile =~ m|^[/\w.\-]+$|) { + if (open(PIPE,"identify $inputfile 2>&1 |")) { + my $imageinfo = ; + if (!close(PIPE)) { + &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile"); + } + chomp($imageinfo); + my ($fullsize) = + ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)\s+/); + if ($fullsize) { + ($fullwidth,$fullheight) = split(/x/,$fullsize); + } + } + } + return ($fullwidth,$fullheight); +} + sub check_configuser { my ($uhome,$dom,$confname,$servadm) = @_; my ($configuserok,%currroles); @@ -1369,17 +1395,23 @@ $env{'user.name'}.':'.$env{'user.domain' if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) { my $inputfile = $filepath.'/'.$file; my $outfile = $filepath.'/'.'tn-'.$file; - my $thumbsize = $thumbwidth.'x'.$thumbheight; - system("convert -sample $thumbsize $inputfile $outfile"); - chmod(0660, $filepath.'/tn-'.$file); - if (-e $outfile) { - my $copyfile=$targetdir.'/tn-'.$file; - if (copy($outfile,$copyfile)) { - print $logfile "\nCopied source to ".$copyfile."\n"; - &write_metadata($dom,$confname,$formname,$targetdir, - 'tn-'.$file,$logfile); - } else { - print $logfile "\nUnable to write ".$copyfile.':'.$!."\n"; + my ($fullwidth,$fullheight) = &check_dimensions($inputfile); + if ($fullwidth ne '' && $fullheight ne '') { + if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) { + my $thumbsize = $thumbwidth.'x'.$thumbheight; + system("convert -sample $thumbsize $inputfile $outfile"); + chmod(0660, $filepath.'/tn-'.$file); + if (-e $outfile) { + my $copyfile=$targetdir.'/tn-'.$file; + if (copy($outfile,$copyfile)) { + print $logfile "\nCopied source to ".$copyfile."\n"; + &write_metadata($dom,$confname,$formname, + $targetdir,'tn-'.$file,$logfile); + } else { + print $logfile "\nUnable to write ".$copyfile. + ':'.$!."\n"; + } + } } } }