Script to find image width x length? (Solved)
Script to find image width x length? (Solved)
Dear puppians,
Is there a native puppy command to get an image size? Width x Length
Or if not native, can someone please lead me to it?
Thanks a lot
Note: the "file" command won't work with. Jppg
Is there a native puppy command to get an image size? Width x Length
Or if not native, can someone please lead me to it?
Thanks a lot
Note: the "file" command won't work with. Jppg
For BMP, GIF, JPG, TGA & TIF you could use exiv2 binary. I think it's present in all of Pups.
As for some other formats, here's a snippet I made some time ago that might be helpful:
Doesn't work with certain .ico files, but otherwise it's quite reliable...
Greetings!
As for some other formats, here's a snippet I made some time ago that might be helpful:
Code: Select all
#!/bin/bash
FILENAME="$1"
[ "$FILENAME" ] || exit 1
FILENAME_TEMP=`echo "$FILENAME" | tr '[:upper:]' '[:lower:]'`
case ${FILENAME_TEMP##*.} in
bmp|gif|png|jpg|jpeg|tga|tif|tiff)
read X Y <<< `exiv2 "$FILENAME" 2>/dev/null | awk '/Image size/ {print $4,$6}'`
;;
ico)
read X Y <<< `file -b "$FILENAME" | awk -F',' '{split($2,a,"x"); print a[1]" "a[2]}'`
;;
pcx)
read X Y <<< `file -b "$FILENAME" | cut -d ']' -f2 | cut -d '[' -f2 | awk -F',' '{print $1+1,$2+1}'`
;;
xpm)
read X Y <<< `grep -m1 "\"" "$FILENAME" | tr -d "\"" | awk '{print $1,$2}'`
;;
svg)
X=`cat "$FILENAME" | tr -d ' \t' | grep -m1 -io "width=".[0-9]* | tr -cd '[[:digit:]]'`
Y=`cat "$FILENAME" | tr -d ' \t' | grep -m1 -io "height=".[0-9]* | tr -cd '[[:digit:]]'`
;;
ppm|pnm)
read X Y <<< `grep -v '#' "$FILENAME" | grep -a -m2 .[0-9] | tail -1 | awk '{print $1,$2}'`
;;
*) echo "Not supported..."; exit 1
esac
echo "$FILENAME: ${X}x${Y}"
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
-
- Posts: 807
- Joined: Mon 12 Oct 2009, 17:11
From your browser (Firefox), right-click on the picture and choose the option about view image info or something like that. Gives you the original dimensions and also that if scaled.
I found your picture is 80px × 62px. See screen shot
B.K. Johnson
[EDIT]
Reread your post and realized you were looking for a command. So my suggestion may not be what you want, however, I am leaving the reply in case someone else finds it useful.
I found your picture is 80px × 62px. See screen shot
B.K. Johnson
[EDIT]
Reread your post and realized you were looking for a command. So my suggestion may not be what you want, however, I am leaving the reply in case someone else finds it useful.
- Attachments
-
- 2Forum-bikeman.jpg
- Output- right-click > View image info of your pic.
- (63.06 KiB) Downloaded 417 times
- ASRI éducation
- Posts: 3197
- Joined: Sat 09 May 2009, 12:10
- Location: France
- Contact:
Re: How to find image width x length?
Hello Flash and B.K. Johnson.trio wrote:Is there a native puppy command to get an image size? Width x Length
Trio is not a novice.
It is probable that he is trying to develop a script.
Graphical interfaces are not going to help ...
Regards
Projet ASRI éducation => [url=http://asri-education.org/]Association[/url] | [url=http://forum.asri-education.org/]Forum[/url] | [url=http://dl01.asri-education.org/]Dépôt[/url] | [url=http://kids.asri-education.org/]Espace kids[/url]
Not sure about native puppy command, but exiv2 can get image size from exif (not that every image has exif saved though)
EDIT: Googled and found an answer on stackoverflow that says that exiv2 will display size even if exif isn't saved, and I just tested it, see second output for image with no exif.
It would be interesting to know though.
If you want to embed image into gtkdialog there are <width></width> and <height></height> tags that will scale image of any size to given values.
EDIT: Googled and found an answer on stackoverflow that says that exiv2 will display size even if exif isn't saved, and I just tested it, see second output for image with no exif.
Code: Select all
13 root:960px$ data=$(exiv2 IMG_5834-960.JPG)
14 root:960px$ echo "$data" | grep "^Image size"
Image size : 640 x 960
Code: Select all
1 root:IMG$ exiv2 2rVyRKI.jpg
File name : 2rVyRKI.jpg
File size : 600887 Bytes
MIME type : image/jpeg
Image size : 2576 x 1719
2rVyRKI.jpg: No Exif data found in the file
If you want to embed image into gtkdialog there are <width></width> and <height></height> tags that will scale image of any size to given values.
puppy.b0x.me stuff mirrored [url=https://drive.google.com/open?id=0B_Mb589v0iCXNnhSZWRwd3R2UWs]HERE[/url] or [url=http://archive.org/details/Puppy_Linux_puppy.b0x.me_mirror]HERE[/url]
See 2005 script posted by Tomchuk
http://ubuntuforums.org/archive/index.php/t-49309.html
I only tested it on one JPG but it seemed to work fine.
Slavvo67
http://ubuntuforums.org/archive/index.php/t-49309.html
I only tested it on one JPG but it seemed to work fine.
Slavvo67
You can try netpbm tools
Eg:
There is also giftopnm, winicontoppm, ppmtogif, bmptoppm ..and so on.
http://netpbm.sourceforge.net
Working example, noisy on the console though
Eg:
Code: Select all
jpegtopnm barrow-v-bolt-meme20.jpg|pnmfile
jpegtopnm: WRITING PPM FILE
stdin: PPM raw, 600 by 800 maxval 255
### for jpeg
pngtopnm stamp99.png|pnmfile|grep [0-9]|awk '{print $4,$6}'
300 200
http://netpbm.sourceforge.net
Working example, noisy on the console though
Code: Select all
#!/bin/sh
usage() {
echo "$0 somepicture|.png|.jpg|.gif|.ico|.bmp"
exit
}
[ "$1" ] || usage
case "$1" in
*.jpg|*.JPG|*.jpeg*|*.JPEG)
APP="jpegtopnm -nosmooth $*" ;;
*.png)
APP="pngtopnm $*" ;;
*.gif)
APP="giftopnm $*" ;;
*.ico) ## doesn't handle compressed .ico
## and is inaccurate because they contain several sizes
APP="winicontoppm $*|ppmtogif|giftopnm" ;;
*.bmp|*.BMP)
APP="bmptoppm $*|ppmtojpeg|jpegtopnm" ;;
*) echo "unsupported" && exit ;;
esac
eval "$APP" |pnmfile|grep [0-9]|awk '{print $4,$6}'
Puppy Linux Blog - contact me for access
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
Since this is a programming thread, I will give some insight on how these tools work to identify the image type and various properties.
First the program has to determine the image type. This is done by looking at specific file offsets for a "magic" string or number. I wrote a reimplementation of file --mime-type that does this pretty efficiently here:
https://github.com/technosaurus/MIMEtype
Once the image type is determined, you can get the image properties from predefined offsets for that image type.
for png the magic at offset 0 is (decimal representation of each byte):
here is a basic template
thisprogram <mypic.png
There is another way to do this using a loop and sets of structs here:
http://landley.net/hg/toybox/file/tip/t ... er/blkid.c
... but with this way you would need extra parameters for the size of each property (some widths may be 16 bits while other formats use 32 ... some audio formats even use only 7 bits of each byte for packet lengths)
see http://www.aivosto.com/vbtips/imageformats.html
XPM is a special case since the text format causes the offset for width and height to be at various offsets due to the variable length name field that is used for embedding in C.
edit - simplified for little endian (x86 and x86_64) example:
First the program has to determine the image type. This is done by looking at specific file offsets for a "magic" string or number. I wrote a reimplementation of file --mime-type that does this pretty efficiently here:
https://github.com/technosaurus/MIMEtype
Once the image type is determined, you can get the image properties from predefined offsets for that image type.
for png the magic at offset 0 is (decimal representation of each byte):
here is a basic template
Code: Select all
#include <stdio.h>
union{
struct { char hdr[8]; int width; int height; }png;
struct { char hdr[5]; char width; char height; }dummy;
}img;
char png_magic[8]={137, 80, 78, 71, 13, 10, 26, 10};
char dummy_magic[5]="dummy";
#define CHECK(x) if(!memcmp(img.x.hdr,x##_magic,sizeof(x##_magic))) \
return !printf("%s %dx%d\n",#x,img.x.width,img.x.height)
int main(void) {
read(0,&img,sizeof(img));
CHECK(png);
else CHECK(dummy);
return 1;
}
There is another way to do this using a loop and sets of structs here:
http://landley.net/hg/toybox/file/tip/t ... er/blkid.c
... but with this way you would need extra parameters for the size of each property (some widths may be 16 bits while other formats use 32 ... some audio formats even use only 7 bits of each byte for packet lengths)
see http://www.aivosto.com/vbtips/imageformats.html
XPM is a special case since the text format causes the offset for width and height to be at various offsets due to the variable length name field that is used for embedding in C.
edit - simplified for little endian (x86 and x86_64) example:
Code: Select all
#include <stdio.h>
union{
struct{short m;char p[16];int w;int h;char P[2];short b;}bmp;
struct{int m;char p[2];short w;short h;char P;char b;}gif;
struct{int m;char p[12];int w;int h;char b;}png;
}i;
int bmp='B'|'M'<<8, gif='G'|'I'<<8|'F'<<16|'8'<<24, png=137|80<<8|78<<16|71<<24;
#define _(x) if(i.x.m==x) return !printf("%s %dx%d@%d\n",#x,i.x.w,i.x.h,i.x.b)
int main(void) {
fread(&i,1,sizeof(i),stdin);
_(png); else _(gif); else _(bmp); else return 1;
}
Last edited by technosaurus on Sat 08 Nov 2014, 06:00, edited 2 times in total.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
Its pretty easy to turn all of those little netpbm programs into a single multicall binary (couple lines of awk on one of the header files and ~ a minute or two of editing) ... I think I sent them a patch already, but I could look into it again. I cut the on disk size drastically even when statically compiled.01micko wrote:You can try netpbm tools
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].