Skip to content

Instantly share code, notes, and snippets.

@georgy7
Last active March 2, 2017 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgy7/560389e1bd0612fa0c34dc2d933457a7 to your computer and use it in GitHub Desktop.
Save georgy7/560389e1bd0612fa0c34dc2d933457a7 to your computer and use it in GitHub Desktop.
Size statictics of WebP on the different levels.
#!/usr/bin/env dub
/+ dub.json:
{
"name": "lalala",
"authors": [
"Георгий Устинов"
],
"license": "Unlicense",
"dependencies": {
"dlib-webp": "~>0.0.6",
"emsi_containers": "~>0.5.2"
}
}
+/
// Usage:
// dub build --single lalala.d
// ./lalala > sizes.csv
import dlib.image;
import dlibwebp;
import containers.treemap;
import std.file;
import std.stdio : writeln, write, writef, stderr;
import std.conv;
import std.path;
const string[] directories = [
"3kImages_webp_q0/",
"3kImages_webp_q24/",
"3kImages_webp_q65/",
"3kImages_webp_q85/",
"3kImages_webp_q95/",
"3kImages_webp_lossless/"
];
void main() {
TreeMap!(string, ulong[]) result;
for (int i = 0; i < directories.length; i++) {
auto files = dirEntries(directories[i],"*.webp", SpanMode.shallow);
foreach (file; files) {
string resultKey = baseName(file.name);
if (!result.containsKey(resultKey)) {
auto row = new ulong[directories.length + 1];
// I know, there is a much faster way to do this, but it's too late. I mean, it's night.
SuperImage image = loadWEBP(file.name);
row[0] = image.width * image.height;
result[resultKey] = row;
}
auto row = result[resultKey];
row[i + 1] = file.size;
result.remove(resultKey);
result[resultKey] = row;
stderr.writef("%s completed\n", resultKey);
}
}
foreach (k; result.keys()) {
write(k, ";");
foreach (number; result[k]) {
write(number, ";");
}
writeln();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment