kareila: (Default)
kareila ([personal profile] kareila) wrote in [site community profile] changelog2009-08-12 06:27 am

[dw-free] Standardize height + width attributes for user icon display

[commit: http://hg.dwscoalition.org/dw-free/rev/efa4d53fc342]

http://bugs.dwscoalition.org/show_bug.cgi?id=926

Properly specify both width and height attributes for scaled userpics.

Patch by [personal profile] draigwen.

Files modified:
  • cgi-bin/LJ/Userpic.pm
  • cgi-bin/bml/scheme/blueshift.look
  • cgi-bin/bml/scheme/celerity.look
  • cgi-bin/bml/scheme/gradation-vertical.look
  • cgi-bin/weblib.pl
--------------------------------------------------------------------------------
diff -r 19969e7506a3 -r efa4d53fc342 cgi-bin/LJ/Userpic.pm
--- a/cgi-bin/LJ/Userpic.pm	Tue Aug 11 16:20:04 2009 -0500
+++ b/cgi-bin/LJ/Userpic.pm	Wed Aug 12 01:27:16 2009 -0500
@@ -331,6 +331,7 @@ sub imgtag {
     # parameters, set them. Otherwise, take what ever is set in
     # the userpic
     my $width = $opts{width} || $self->width;
+    my $height = $opts{height} || $self->height;
     my $keyword = $opts{keyword} || $self->keywords;
 
     # if no description is available for alttext, try to fall
@@ -351,8 +352,9 @@ sub imgtag {
     }    
     $title = LJ::ehtml( $title );
 
-    return '<img src="' . $self->url . '" width="' . $width .
-        '" alt="' . $alttext . '" title="' . $title . '" class="userpic-img" />';
+    return '<img src="' . $self->url . '" width="' . $width . 
+        '" height="' . $height . '" alt="' . $alttext . 
+        '" title="' . $title . '" class="userpic-img" />';
 }
 
 # FIXME: should have alt text, if it should be kept
@@ -379,6 +381,33 @@ sub imgtag_percentagesize {
 
     return '<img src="' . $self->url . '" width="' . $width . '" height="' . $height . '" class="userpic-img" />';
 }
+
+# pass a fixed height or width that you want to be the size of the userpic
+# must include either a height or width, if both are given the smaller of the two is used
+# returns the width and height attributes as a string to insert into an img tag
+sub img_fixedsize {
+    my $self = shift;
+    my %opts = @_;
+
+    my $width = $opts{width} || 0;
+    my $height = $opts{height} || 0;
+
+    if ( $width > 0 && $width < $self->width && 
+        ( !$height || ( $width <= $height && $self->width >= $self->height ) ) ) {
+        my $ratio = $width / $self->width;
+        $height = int( $self->height * $ratio );
+    } elsif ( $height > 0 && $height < $self->height ) {
+        my $ratio = $height / $self->height;
+        $width = int( $self->width * $ratio );
+    } else {
+        $width = $self->width;
+        $height = $self->height;
+    }
+
+    return 'height="' . $height . '" width="' . $width . '"';
+}
+
+
 
 # in scalar context returns comma-seperated list of keywords or "pic#12345" if no keywords defined
 # in list context returns list of keywords ( (pic#12345) if none defined )
diff -r 19969e7506a3 -r efa4d53fc342 cgi-bin/bml/scheme/blueshift.look
--- a/cgi-bin/bml/scheme/blueshift.look	Tue Aug 11 16:20:04 2009 -0500
+++ b/cgi-bin/bml/scheme/blueshift.look	Wed Aug 12 01:27:16 2009 -0500
@@ -65,20 +65,14 @@ accountlinks<=
         my $inbox = $remote->notification_inbox;
         my $unread = $inbox->unread_count;
         my $identity = $remote->is_identity;
-        my $wh = "";
-        if ( $userpic ) {
-            if ( $userpic->width > $userpic->height ) {
-                $wh = 'width="' . ( $userpic->width > 80 ? 80 : $userpic->width ) . '"';
-            } else {
-                $wh = 'height="' . ( $userpic->height > 80 ? 80 : $userpic->height ) . '"';
-            }
-        }
 
         $ret .= "<div id='account-links-userpic'><a href='$LJ::SITEROOT/editpics'>";
+
         if ( $userpic ) {
+            my $wh = $userpic->img_fixedsize( width => 80, height => 80 );
             $ret .= "<img src='" . $userpic->url . "' $wh alt=\"$ML{'sitescheme.accountlinks.userpic.alt'}\" />";
         } else {
-            $ret .= "<img src='$LJ::IMGPREFIX/nouserpic.png' width='80' alt=\"$ML{'sitescheme.accountlinks.userpic.alt'}\" />";
+            $ret .= "<img src='$LJ::IMGPREFIX/nouserpic.png' width='80' height='80' alt=\"$ML{'sitescheme.accountlinks.userpic.alt'}\" />";
         }
         $ret .= "</a></div>";
         $ret .= "<div id='account-links-text'>";
diff -r 19969e7506a3 -r efa4d53fc342 cgi-bin/bml/scheme/celerity.look
--- a/cgi-bin/bml/scheme/celerity.look	Tue Aug 11 16:20:04 2009 -0500
+++ b/cgi-bin/bml/scheme/celerity.look	Wed Aug 12 01:27:16 2009 -0500
@@ -64,7 +64,6 @@ accountlinks<=
         my $inbox = $remote->notification_inbox;
         my $unread = $inbox->unread_count;
         my $identity = $remote->is_identity;
-        my $wh = "";
 
         $ret .= "<div id='account-links-text'>";
         $ret .= "<form action='$LJ::SITEROOT/logout?ret=1' method='post'>";
@@ -151,14 +150,10 @@ userpic<=
     if ( $remote ) {
         my $userpic = $remote->userpic;
         if ( $userpic && !$LJ::IS_SSL ) {
-            if ( $userpic->width > $userpic->height ) {
-                $wh = 'width="' . ( $userpic->width > 80 ? 80 : $userpic->width ) . '"';
-            } else {
-                $wh = 'height="' . ( $userpic->height > 80 ? 80 : $userpic->height ) . '"';
-            }
+            my $wh = $userpic->img_fixedsize( width => 80, height => 80 );
             $ret .= "<img src='" . $userpic->url . "' $wh alt=\"$ML{'sitescheme.accountlinks.userpic.alt'}\" />";
         } else {
-            $ret .= "<img src='$imgprefix/nouserpic.png' width='80' alt=\"$ML{'sitescheme.accountlinks.userpic.alt'}\" />";
+            $ret .= "<img src='$imgprefix/nouserpic.png' width='80' height='80' alt=\"$ML{'sitescheme.accountlinks.userpic.alt'}\" />";
         }
     }
 
diff -r 19969e7506a3 -r efa4d53fc342 cgi-bin/bml/scheme/gradation-vertical.look
--- a/cgi-bin/bml/scheme/gradation-vertical.look	Tue Aug 11 16:20:04 2009 -0500
+++ b/cgi-bin/bml/scheme/gradation-vertical.look	Wed Aug 12 01:27:16 2009 -0500
@@ -65,20 +65,13 @@ accountlinks<=
         my $inbox = $remote->notification_inbox;
         my $unread = $inbox->unread_count;
         my $identity = $remote->is_identity;
-        my $wh = "";
-        if ( $userpic ) {
-            if ( $userpic->width > $userpic->height ) {
-                $wh = 'width="' . ( $userpic->width > 80 ? 80 : $userpic->width ) . '"';
-            } else {
-                $wh = 'height="' . ( $userpic->height > 80 ? 80 : $userpic->height ) . '"';
-            }
-        }
 
         $ret .= "<div id='account-links-userpic'><a href='$LJ::SITEROOT/editpics'>";
         if ( $userpic ) {
+            my $wh = $userpic->img_fixedsize( width => 80, height => 80 );
             $ret .= "<img src='" . $userpic->url . "' $wh alt=\"$ML{'sitescheme.accountlinks.userpic.alt'}\" />";
         } else {
-            $ret .= "<img src='$LJ::IMGPREFIX/nouserpic.png' width='80' alt=\"$ML{'sitescheme.accountlinks.userpic.alt'}\" />";
+            $ret .= "<img src='$LJ::IMGPREFIX/nouserpic.png' width='80' height='80' alt=\"$ML{'sitescheme.accountlinks.userpic.alt'}\" />";
         }
         $ret .= "</a></div>";
         $ret .= "<div id='account-links-text'>";
diff -r 19969e7506a3 -r efa4d53fc342 cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl	Tue Aug 11 16:20:04 2009 -0500
+++ b/cgi-bin/weblib.pl	Wed Aug 12 01:27:16 2009 -0500
@@ -2571,9 +2571,11 @@ sub control_strip
     my $ret;
     if ($remote) {
         my $remote_display  = LJ::ljuser($remote);
-        if ($remote->{'defaultpicid'}) {
-            my $url = "$LJ::USERPIC_ROOT/$remote->{'defaultpicid'}/$remote->{'userid'}";
-            $ret .= "<td id='lj_controlstrip_userpic' style='background-image: none;'><a href='$LJ::SITEROOT/editpics'><img src='$url' alt=\"$BML::ML{'web.controlstrip.userpic.alt'}\" title=\"$BML::ML{'web.controlstrip.userpic.title'}\" height='43' /></a></td>";
+        my $userpic = $remote->userpic;
+        if ( $userpic ) {
+            my $wh = $userpic->img_fixedsize( width => 43, height => 43 );
+            $ret .= "<td id='lj_controlstrip_userpic' style='background-image: none;'><a href='$LJ::SITEROOT/editpics'>";
+            $ret .= "<img src='" . $userpic->url . "' alt=\"$BML::ML{'web.controlstrip.userpic.alt'}\" title=\"$BML::ML{'web.controlstrip.userpic.title'}\" $wh /></a></td>";
         } else {
             my $tinted_nouserpic_img = "";
 
@@ -2591,10 +2593,11 @@ sub control_strip
             }
             $ret .= "<td id='lj_controlstrip_userpic' style='background-image: none;'><a href='$LJ::SITEROOT/editpics'>";
             if ($tinted_nouserpic_img eq "") {
-                $ret .= "<img src='$LJ::IMGPREFIX/controlstrip/nouserpic.gif' alt=\"$BML::ML{'web.controlstrip.nouserpic.alt'}\" title=\"$BML::ML{'web.controlstrip.nouserpic.title'}\" height='43' />";
+                $ret .= "<img src='$LJ::IMGPREFIX/controlstrip/nouserpic.gif' ";
             } else {
-                $ret .= "<img src='$tinted_nouserpic_img' alt=\"$BML::ML{'web.controlstrip.nouserpic.alt'}\" title=\"$BML::ML{'web.controlstrip.nouserpic.title'}\" height='43' />";
+                $ret .= "<img src='$tinted_nouserpic_img' ";
             }
+            $ret .= "alt=\"$BML::ML{'web.controlstrip.nouserpic.alt'}\" title=\"$BML::ML{'web.controlstrip.nouserpic.title'}\" height='43' width='43' />";
             $ret .= "</a></td>";
         }
         $ret .= "<td id='lj_controlstrip_user' nowrap='nowrap'><form id='Greeting' class='nopic' action='$LJ::SITEROOT/logout?ret=1' method='post'><div>";
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org