From 5e815e0b2390affad0677d0cbcb480f4aadbae9f Mon Sep 17 00:00:00 2001
From: Thomas Steur <thomas.steur@googlemail.com>
Date: Mon, 26 May 2014 01:11:58 +0200
Subject: [PATCH] fixes #5203 keep transparency when uploading logo, also
 improves quality of generated logo

---
 plugins/CoreAdminHome/CustomLogo.php       | 19 +++++++++----------
 plugins/Dashboard/javascripts/dashboard.js |  1 +
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/plugins/CoreAdminHome/CustomLogo.php b/plugins/CoreAdminHome/CustomLogo.php
index 1483e83ec6..79aa7de71d 100644
--- a/plugins/CoreAdminHome/CustomLogo.php
+++ b/plugins/CoreAdminHome/CustomLogo.php
@@ -195,21 +195,20 @@ class CustomLogo
                 return false;
         }
 
-        $smallWidthExpected = round($width * $targetHeight / $height);
+        $targetWidth = round($width * $targetHeight / $height);
 
-        $logoSmall = imagecreatetruecolor($smallWidthExpected, $targetHeight);
-
-        // Handle transparency
-        $backgroundSmall = imagecolorallocate($logoSmall, 0, 0, 0);
-        imagecolortransparent($logoSmall, $backgroundSmall);
+        $newImage = imagecreatetruecolor($targetWidth, $targetHeight);
 
         if ($_FILES[$uploadFieldName]['type'] == 'image/png') {
-            imagealphablending($logoSmall, false);
-            imagesavealpha($logoSmall, true);
+            imagealphablending($newImage, false);
+            imagesavealpha($newImage, true);
         }
 
-        imagecopyresized($logoSmall, $image, 0, 0, 0, 0, $smallWidthExpected, $targetHeight, $width, $height);
-        imagepng($logoSmall, PIWIK_DOCUMENT_ROOT . '/' . $userPath, 3);
+        $backgroundColor = imagecolorallocate($newImage, 0, 0, 0);
+        imagecolortransparent($newImage, $backgroundColor);
+
+        imagecopyresampled($newImage, $image, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height);
+        imagepng($newImage, PIWIK_DOCUMENT_ROOT . '/' . $userPath, 3);
         return true;
     }
 
diff --git a/plugins/Dashboard/javascripts/dashboard.js b/plugins/Dashboard/javascripts/dashboard.js
index 85e8d37cf0..9ec9cd1b7d 100644
--- a/plugins/Dashboard/javascripts/dashboard.js
+++ b/plugins/Dashboard/javascripts/dashboard.js
@@ -8,6 +8,7 @@
 function initDashboard(dashboardId, dashboardLayout) {
 
     $('.dashboardSettings').show();
+    initTopControls();
 
     // Embed dashboard
     if (!$('#topBars').length) {
-- 
GitLab