mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
Add example for printing <img> tag
This commit is contained in:
parent
a7bd4ed9ea
commit
cfbd2afc19
1 changed files with 29 additions and 0 deletions
29
examples/img.c
Normal file
29
examples/img.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#if 0
|
||||||
|
/*─────────────────────────────────────────────────────────────────╗
|
||||||
|
│ To the extent possible under law, Justine Tunney has waived │
|
||||||
|
│ all copyright and related or neighboring rights to this file, │
|
||||||
|
│ as it is written in the following disclaimers: │
|
||||||
|
│ • http://unlicense.org/ │
|
||||||
|
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||||
|
╚─────────────────────────────────────────────────────────────────*/
|
||||||
|
#endif
|
||||||
|
#include "libc/stdio/stdio.h"
|
||||||
|
#include "libc/x/x.h"
|
||||||
|
#include "third_party/stb/stb_image.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fileoverview Utility for printing HTML <img> tags.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
void *p;
|
||||||
|
size_t n;
|
||||||
|
int yn, xn, cn;
|
||||||
|
if (argc != 2) return 1;
|
||||||
|
if (!(p = xslurp(argv[1], &n))) return 2;
|
||||||
|
if (!(p = stbi_load_from_memory(p, n, &xn, &yn, &cn, 0))) return 3;
|
||||||
|
printf("<img src=\"%s\" width=\"%d\" height=\"%d\"\n"
|
||||||
|
" alt=\"[%s]\">\n",
|
||||||
|
argv[1], (xn + 1) >> 1, (yn + 1) >> 1, argv[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue