Page 1 of 1
Get-Image-Size
Posted: Wed 06 Feb 2019, 12:36
by rcrsn51
Here is a little tool named get-image-size that can extract the dimensions of a graphic file and assign them to variables. For example:
Code: Select all
read WIDTH HEIGHT <<< $(get-image-size photo.jpg)
echo width=$WIDTH height=$HEIGHT
The attached tarball contains 32/64bit versions. Rename the one you need and copy it to /usr/local/bin.
Posted: Wed 06 Feb 2019, 13:49
by musher0
Thanks, rcrsn51.
One could alternatively use utilities from the netpbm suite:
Code: Select all
jpegtopnm X.jpg > X.pnm
pamfile X.pnm
Source.
But yours saves a step.
BFN.
Posted: Wed 06 Feb 2019, 14:23
by rcrsn51
and assign them to variables
What's the point in demonstrating code that doesn't accomplish the objective?
If I was willing to use more code that extracts the dimensions from pamfile, I wouldn't have bothered developing this tool.
Posted: Wed 06 Feb 2019, 17:40
by musher0
Of course.
Posted: Wed 06 Feb 2019, 19:27
by vovchik
Dear rcrsn51,
Thanks very much. I once did something similar using the STB library, but your code is tiny. Can you please post your source, so that I can see how you do it? I see it handles xmp, png, gif, jpg, bmp and svg nicely. I would also like to compile it for my RPI3.
With kind regards,
vovchik
Posted: Wed 06 Feb 2019, 19:47
by rcrsn51
Attached. It is based on mu's work
here.
Posted: Wed 06 Feb 2019, 20:50
by vovchik
Dear rcrsn51,
Thanks for the source. It looks familiar.
![Smile :)](./images/smilies/icon_smile.gif)
I use those same fucntions from the gdk pixbuf loader in my picscale. In my STB-based getsize, there is no external dependency (gdk/gtk2), but the binary is significantly larger, so your little utility is probably better for most purposes and on most platforms.
It works nicely on RPI3, too. I have attached an armv7 (jessie) binary for the RPI3.
Thanks again.
With kind regards,
vovchik