summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authormoontear <[email protected]>2013-04-15 12:28:52 +0200
committermoontear <[email protected]>2013-04-15 12:28:52 +0200
commit2cfbb448fb197837c063c377c042beb3ba704a52 (patch)
treea114be33e5343cedb17391d50339e7cd2da14a5f /include
parente43a9c4a01bf095b740e35711c79f6a0ca3374ba (diff)
Added average color calculation of feeds' favicons for banded display.
Diffstat (limited to 'include')
-rw-r--r--include/functions.php42
-rw-r--r--include/rssfuncs.php11
2 files changed, 50 insertions, 3 deletions
diff --git a/include/functions.php b/include/functions.php
index e2357f6c0..1ae5bbbe2 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -508,8 +508,50 @@
}
}
}
+ return $icon_file;
}
}
+
+ function calculate_avg_color($iconFile) {
+
+ require_once "lib/floIcon.php";
+
+ $imgInfo = @getimagesize($iconFile);
+
+ if(strtolower($imgInfo['mime'])=='image/vnd.microsoft.icon') {
+ $ico = new floIcon();
+ @$ico->readICO($iconFile);
+ //TODO: error logging
+ if(count($ico->images)==0)
+ return null;
+ else {
+ $image = @$ico->images[count($ico->images)-1]->getImageResource();
+ }
+ $type = "ico";
+ }
+ elseif(strtolower($imgInfo['mime'])=='image/png') {
+ $image = imagecreatefrompng($iconFile);
+ $type = 'png';
+ }
+ elseif(strtolower($imgInfo['mime'])=='image/jpeg') {
+ $image = imagecreatefromjpeg($iconFile);
+ $type = 'jpg';
+ }
+ elseif(strtolower($imgInfo['mime'])=='image/gif') {
+ $image = imagecreatefromgif($iconFile);
+ $type = 'gif';
+ }
+ //TODO: error logging
+ if (is_null($image))
+ return null;
+ $width = imagesx($image);
+ $height = imagesy($image);
+ $pixel = imagecreatetruecolor(1, 1);
+ imagecopyresampled($pixel, $image, 0, 0, 0, 0, 1, 1, $width, $height);
+ $rgb = imagecolorat($pixel, 0, 0);
+ $color = imagecolorsforindex($pixel, $rgb);
+ return $color;
+ }
function print_select($id, $default, $values, $attributes = "") {
print "<select name=\"$id\" id=\"$id\" $attributes>";
diff --git a/include/rssfuncs.php b/include/rssfuncs.php
index 859c575cc..498700906 100644
--- a/include/rssfuncs.php
+++ b/include/rssfuncs.php
@@ -408,9 +408,14 @@
}
if ($favicon_needs_check) {
- check_feed_favicon($site_url, $feed, $link);
-
- db_query($link, "UPDATE ttrss_feeds SET favicon_last_checked = NOW()
+ $favicon_file = check_feed_favicon($site_url, $feed, $link);
+ if ($favicon_file) {
+ $favicon_color = calculate_avg_color($favicon_file);
+ if (is_array($favicon_color))
+ $favicon_colorstring = ",favicon_avg_color = '" . implode("|", array_slice($favicon_color, 0, 3)) . "'";
+ }
+
+ db_query($link, "UPDATE ttrss_feeds SET favicon_last_checked = NOW() $favicon_colorstring
WHERE id = '$feed'");
}