From b073f2e0d6f19bb49a3e6aa8dd8878a61b1a6d55 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 25 Nov 2018 07:23:20 +0100 Subject: [PATCH] Added support for different sizes --- CMakeLists.txt | 2 +- README.md | 20 ++++++++++++++------ src/libravatarserv.cpp | 16 ++++++++++++++-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a332c12..4b3c345 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.2) project(libravatarserv - VERSION 0.1.0 + VERSION 0.2.0 LANGUAGES CXX ) diff --git a/README.md b/README.md index c631d5e..29ac304 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,6 @@ images tied to email or OpenID addresses. * Default avatar for unknown addresses * MD5 hashes * SHA256 hashes - -### Soon - * Variable image size (`s`) ### Not supported @@ -33,9 +30,20 @@ libravatarserv looks in each of `${XDG_DATA_DIRS}` for a directory named `libravatarserv`. You can force a different directory by setting the environment variable `${AVATAR_DIR}`. -The image files are named like your email address, no file extension. Example: -`user@example.com`. If you want to deliver a default image for unknown email -addresses, name it `default`. +The image files are named like your email address, no file extension. If you +want to deliver a default image for unknown email addresses, name it `default`. + +Test your setup on https://www.libravatar.org/tools/check/. + +### Example + +A directory could look like this: +```PLAIN +/usr/share/libravatarserv +├── [ 32K] default +├── [ 759] user@example.com +└── [ 16] user+newsletter@example.com -> user@example.com +``` ## Install diff --git a/src/libravatarserv.cpp b/src/libravatarserv.cpp index f1394b6..53085ec 100644 --- a/src/libravatarserv.cpp +++ b/src/libravatarserv.cpp @@ -58,14 +58,26 @@ int main() cout << "Content-type: image/png\n\n"; cout.flush(); // We need to flush before we use /dev/stdout directly. + uint16_t size = 80; string digest = request.substr(8); std::transform(digest.begin(), digest.end(), digest.begin(), ::tolower); + std::size_t pos = digest.find('?'); + if (pos != std::string::npos) + { + pos = digest.find("s=", pos); + if (pos != std::string::npos) + { + size = static_cast(std::stoul(digest.substr(pos + 2))); + cout << size << endl; + } + digest = digest.substr(0, pos); + } - image::Image answer = image::get(digest, 80); + image::Image answer = image::get(digest, size); if (answer.error == 0) { // answer.image.write("test.png"); - answer.image.write("/dev/stdout"); + // answer.image.write("/dev/stdout"); } else {