Width & Height info with gmic cli?

By merely invoking G’MIC on the command line and passing the image name, a good amount of information is presented:

root@localhost:/storage/...# gmic 3135.jpg
[gmic]./ Start G'MIC interpreter (v.3.6.5).
[gmic]./ Input file '3135.jpg' at position 0 (1 image 2272x1704x1x3).
[gmic]./ Print image [0] = '3135.jpg'.
[0] = '3135.jpg':
  size = (2272,1704,1,3) [44.3 Mio of float32].
  data = (15,15,15,14,14,13,13,13,17,17,17,17,17,17,17,17,18,18,18,19,19,20,20,20,23,23,23,23,23,23,23,23,18,19,21,22,23,22,21,20,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,22,22,22,21,21,20,20,20, ... ,17,18,19,23,33,42,52,55,11,29,35,43,78,87,57,29,4,28,54,39,0,2,35,41,32,0,0,5,4,14,20,0,0,0,13,8,0,0,0,0,13,54,69,61,41,33,57,63,0,90,159,147,107,84,65,43,43,21,31,77,98,54,17,20).
  min = 0, max = 255, mean = 84.9305, std = 63.8985, coords_min = (560,54,0,0), coords_max = (1411,127,0,0).
[gmic]./ End G'MIC interpreter.

Is there a command that will just show the width and height dimensions only?

Hi, yes, something like this :

:~$ gmic v 0 image.ext foreach echo \{w\},\{h\}\\n done
1000,1000

I used foreach ... done so you can load multiple images, just in case, but you can remove it.
v 0 so g’mic will be quiet(er).

With name :slight_smile:

:~$ gmic v 0 empty_1000.png gmic_000001.png  foreach echo \{n\},\{w\},\{h\}\\n done
empty_1000.png,1000,1000

gmic_000001.png,1280,1280

if you don’t wan’t to escape the "{ } " you can use run with single quotes around the command. (at least on Linux).

gmic v 0 empty_1000.png gmic_000001.png run 'foreach echo {n},{w},{h}\\n done'

EDIT : this works too (no { }):

gmic v 0 *.png foreach eval "echo(name(),',',w,',',h)" done  

empty_1000.png,1000,1000
gmic_000000.png,1280,1280
gmic_000001.png,1280,1280
gmic_000002.png,1280,1280
gmic_000003.png,1280,1280
gmic_000004.png,1280,1280
1 Like

Thanks @prawnsushi !!

I hit upon this way of doing it, and was just about to report back:
gmic v -99 3135.jpg -echo "{w#0},{h#0}" -echo ""

I will use the gmic v 0 3135.jpg foreach echo \{w\},\{h\}\\n done approach.

Nice to have a more canonical version, good stuff!

mmm i wouldn’t say it’s a canonical way of doing it, only @David_Tschumperle could write one i guess :p, But thanks anyway!

your version works fine too, but if you only load one image you don’t need to add the index #0 .
and with G’mic, the shortest way you can go, the better!
So your version can become :
$ gmic v 0 3135.jpg e "{w},{h}\n"

1 Like