Get-Image-Size

Paint programs, vector editors, 3d modelers, animation editors, etc.
Post Reply
Message
Author
User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

Get-Image-Size

#1 Post 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.
Attachments
get-image-size.tar.gz
(3.86 KiB) Downloaded 262 times

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#2 Post 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.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#3 Post 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.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#4 Post by musher0 »

Of course.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#5 Post 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

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#6 Post by rcrsn51 »

Attached. It is based on mu's work here.
Attachments
get-image-size-source.tar.gz
(594 Bytes) Downloaded 272 times

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#7 Post by vovchik »

Dear rcrsn51,

Thanks for the source. It looks familiar. :) 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
Attachments
get-image-size-armv7-jessie-rp3.tar.gz
(2.23 KiB) Downloaded 257 times

Post Reply