What is the most simple way to read image, flip or rotate (for example) and write back?
tried many ways from here https://forum.nim-lang.org/t/3056
half of libs are not working/legacy, the rest methods aren't pretty (operating with C pointers/strings etc.)
You'll have to deal with them for now, as the Nim ecosystem is not that big yet. It's not too hard to provide abstractions for cstrings, as Nim's string can be converted implicitly to them.
If you're on Linux, gdk-pixbuf is a viable choice (bindings provided by gintro package). Here's a CLI tool that flip and rotate an image of choice.
import os, parseopt
import gintro / gdkpixbuf
var
filename: string
output: string
for kind, key, val in getopt():
case kind
of cmdArgument:
filename = key
of cmdLongOption, cmdShortOption:
case key
of "o", "output":
output = val
else: discard
if filename.len < 1:
quit "No file specified"
if output.len < 1:
output = filename.changeFileExt "modified.png"
let outputType = output[output.searchExtPos + 1..^1]
if outputType.len < 1:
quit "Invalid output type"
var pix = newPixbufFromFile filename
pix = pix.flip true
pix = pix.rotateSimple PixbufRotation.counterclockwise
discard pix.savev(output, outputType, [])
https://github.com/SolitudeSF/imageman
its heavily wip but it works. if something doesnt work or functionality is missing, issue on github would be much appreciated.
Thanks for example. I have never found time to learn about gtk-pixbuf myself.
Of course gintro can work on Windows as well, some Nim users have managed to install it. But of course most Windows users just don't want to use GTK.