Added support for different sizes

This commit is contained in:
tastytea 2018-11-25 07:23:20 +01:00
parent 30ec8f0657
commit b073f2e0d6
Signed by untrusted user: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 29 additions and 9 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.2)
project(libravatarserv
VERSION 0.1.0
VERSION 0.2.0
LANGUAGES CXX
)

View File

@ -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

View File

@ -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<uint16_t>(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
{