Skip to content

Instantly share code, notes, and snippets.

@v1993
Last active January 25, 2019 20:32
Show Gist options
  • Save v1993/e01082d6b4c6ef00f576ab943b7db2b0 to your computer and use it in GitHub Desktop.
Save v1993/e01082d6b4c6ef00f576ab943b7db2b0 to your computer and use it in GitHub Desktop.
// Show image using dots and spaces in terminal
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include <iostream>
int main(int argc, char *argv[]) {
if (argc != 2) { std::cerr << "Only one argument should be image file" << std::endl; return 1; };
int x, y, n;
unsigned char *data = stbi_load(argv[1], &x, &y, &n, 1);
if (!data) { std::cerr << "Error loading file" << std::endl; return 1; };
std::cout << "x, y, bpp: " << x << ", " << y << ", " << n << std::endl;
for (int yi = 0; yi < y; yi+=2) { // In my terminal this makes resolution close to correct
for (int xi = 0; xi < x; ++xi) {
std::cout << ((data[yi*x+xi] > 128) ? (" ") : ("."));
}
std::cout << std::endl;
}
stbi_image_free(data);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment