[Rt-commit] rt branch, 4.0/replace-imager-with-gd, created. rt-4.0.0rc6-6-g82343ce

Thomas Sibley trs at bestpractical.com
Fri Mar 4 10:09:02 EST 2011


The branch, 4.0/replace-imager-with-gd has been created
        at  82343ce508666604a41f874178186baf859a3b3e (commit)

- Log -----------------------------------------------------------------
commit 8ddc190237ccc28cf82a38252c098e5f4eee1cb5
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed Mar 2 15:00:21 2011 -0500

    Replace Imager with GD since we already depend on GD for charts
    
    There is no need for multiple image processing libraries in this case
    since we just need pixel RGB data.

diff --git a/README b/README
index e8106be..fd23960 100644
--- a/README
+++ b/README
@@ -97,11 +97,9 @@ GENERAL INSTALLATION
     If you are unsure of your CPAN version, it will be printed when you run the
     shell.
 
-    If you are having trouble installing Imager::File::GIF/PNG/JPEG, you will
-    need the appropriate development libraries (giflib-devel, libpng-devel and
-    libjpeg-devel are the rpm names for these libraries).  You may also want to
-    install gd-devel at this time, along with the graphviz rpms (available from
-    graphviz.org) if you want to use graphs and charts.
+    If you are having trouble installing GD or Graphviz, you should install
+    gd-devel and the graphviz libraries using your distribution's package
+    manager.
 
 5   Check to make sure everything was installed properly.
 
diff --git a/sbin/rt-test-dependencies.in b/sbin/rt-test-dependencies.in
index 8ddcfad..e54ee31 100755
--- a/sbin/rt-test-dependencies.in
+++ b/sbin/rt-test-dependencies.in
@@ -344,10 +344,6 @@ GD::Text
 .
 
 $deps{'USERLOGO'} = [ text_to_hash( << '.') ];
-Imager
-Imager::File::GIF
-Imager::File::JPEG
-Imager::File::PNG
 Convert::Color
 .
 
diff --git a/share/html/Admin/Global/Theme.html b/share/html/Admin/Global/Theme.html
index 0d79ebd..35b7e94 100644
--- a/share/html/Admin/Global/Theme.html
+++ b/share/html/Admin/Global/Theme.html
@@ -192,7 +192,7 @@ my $text_threshold = 0.6;
 my @results;
 
 my $has_color_analyzer =
-eval { require Imager; require Convert::Color; 1 };
+eval { require GD; require Convert::Color; 1 };
 
 my $img;
 if (my $file_hash = _UploadedFile( 'logo-upload' )) {
@@ -203,9 +203,8 @@ if (my $file_hash = _UploadedFile( 'logo-upload' )) {
                                                     data => $file_hash->{LargeContent} } );
     push @results, loc("Unable to set UserLogo: [_1]", $msg) unless $id;
 
-    $img = Imager->new;
-    unless ( $img->read(data => $file_hash->{LargeContent}) ) {
-        push @results, loc("Unable to read image: [_1]", $img->errstr);
+    unless ( $img = GD::Image->new($file_hash->{LargeContent}) ) {
+        push @results, loc("Unable to read image");
         undef $img;
     }
 }
@@ -216,9 +215,8 @@ else {
     if (my $attr = RT->System->FirstAttribute('UserLogo')) {
         my $content = $attr->Content;
         if (ref($content) eq 'HASH') {
-            $img = Imager->new;
-            unless ( $img->read(data => $content->{data}) ) {
-                push @results, loc("Unable to read image: [_1]", $img->errstr);
+            unless ( $img = GD::Image->new($content->{data}) ) {
+                push @results, loc("Unable to read image");
                 undef $img;
             }
         }
@@ -260,10 +258,9 @@ sub analyze_img {
     my $img = shift;
     my $color;
 
-    for my $i (0..$img->getwidth-1) {
-        for my $j (0..$img->getheight-1) {
-            my @color = $img->getpixel(x=>$i, y=>$j)->rgba;
-            pop @color;
+    for my $i (0..$img->width-1) {
+        for my $j (0..$img->height-1) {
+            my @color = $img->rgb( $img->getPixel($i,$j) );
             my $hsl = Convert::Color->new('rgb:'.join(',',map { $_ / 255 } @color))->convert_to('hsl');
             my $c = join(',', at color);
             next if $hsl->lightness < 0.1;

commit 82343ce508666604a41f874178186baf859a3b3e
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed Mar 2 15:32:17 2011 -0500

    Refactor image analyzing to respect the DisableGD flag

diff --git a/share/html/Admin/Global/Theme.html b/share/html/Admin/Global/Theme.html
index 35b7e94..23bd7ce 100644
--- a/share/html/Admin/Global/Theme.html
+++ b/share/html/Admin/Global/Theme.html
@@ -56,7 +56,7 @@
 <div id="simple-customize">
 <div id="upload-logo">
   <h2>Logo</h2>
-% if ($img) {
+% if ($imgdata) {
   <img src="<% RT->Config->Get('WebPath') %>/NoAuth/Helpers/CustomLogo?<% time() %>" />
 % }
   <form method="POST" enctype="multipart/form-data">
@@ -190,11 +190,8 @@ require JSON;
 
 my $text_threshold = 0.6;
 my @results;
+my $imgdata;
 
-my $has_color_analyzer =
-eval { require GD; require Convert::Color; 1 };
-
-my $img;
 if (my $file_hash = _UploadedFile( 'logo-upload' )) {
     my ($id, $msg) = RT->System->SetAttribute( Name => "UserLogo",
                                                 Description => "User-provided logo",
@@ -203,10 +200,7 @@ if (my $file_hash = _UploadedFile( 'logo-upload' )) {
                                                     data => $file_hash->{LargeContent} } );
     push @results, loc("Unable to set UserLogo: [_1]", $msg) unless $id;
 
-    unless ( $img = GD::Image->new($file_hash->{LargeContent}) ) {
-        push @results, loc("Unable to read image");
-        undef $img;
-    }
+    $imgdata = $file_hash->{LargeContent};
 }
 elsif ($ARGS{'reset_logo'}) {
     RT->System->DeleteAttribute('UserLogo');
@@ -215,10 +209,7 @@ else {
     if (my $attr = RT->System->FirstAttribute('UserLogo')) {
         my $content = $attr->Content;
         if (ref($content) eq 'HASH') {
-            unless ( $img = GD::Image->new($content->{data}) ) {
-                push @results, loc("Unable to read image");
-                undef $img;
-            }
+            $imgdata = $content->{data};
         }
         else {
             RT->System->DeleteAttribute('UserLogo');
@@ -251,9 +242,24 @@ if (!$user_css) {
 
 # XXX: move this to some other modules
 
-my $colors = $img && $has_color_analyzer? analyze_img($img) : undef;
 use List::MoreUtils qw(uniq);
 
+my $has_color_analyzer = eval { require Convert::Color; 1 };
+my $colors;
+
+if (    $imgdata
+    and not RT->Config->Get('DisableGD')
+    and $has_color_analyzer)
+{
+    require GD;
+    if ( my $img = GD::Image->new($imgdata) ) {
+        $colors = analyze_img($img);
+    }
+    else {
+        push @results, loc("Unable to read image");
+    }
+}
+
 sub analyze_img {
     my $img = shift;
     my $color;

-----------------------------------------------------------------------


More information about the Rt-commit mailing list