Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 31 Oct 2014, 11:58
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Script to find image width x length? (Solved)
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [10 Posts]  
Author Message
trio


Joined: 21 Dec 2008
Posts: 1817
Location: अनुमोदना

PostPosted: Tue 21 Oct 2014, 07:10    Post subject:  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

_________________
PET Maker|EasyLauncher
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1081

PostPosted: Tue 21 Oct 2014, 08:44    Post subject:  

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:
Code:
#!/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}"

Doesn't work with certain .ico files, but otherwise it's quite reliable...

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11128
Location: Arizona USA

PostPosted: Tue 21 Oct 2014, 09:58    Post subject:  

mtPaint shows the image size, at the bottom left corner. Right-click on the file, then choose Open with -> mtPaint.
Back to top
View user's profile Send private message 
B.K. Johnson

Joined: 12 Oct 2009
Posts: 141

PostPosted: Tue 21 Oct 2014, 12:07    Post subject:  

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.
2Forum-bikeman.jpg
 Description   Output- right-click > View image info of your pic.
 Filesize   63.06 KB
 Viewed   207 Time(s)

2Forum-bikeman.jpg

Back to top
View user's profile Send private message 
ASRI éducation


Joined: 09 May 2009
Posts: 2555
Location: France

PostPosted: Tue 21 Oct 2014, 16:14    Post subject: Re: How to find image width x length?  

trio wrote:
Is there a native puppy command to get an image size? Width x Length

Hello Flash and B.K. Johnson.
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 => Association | Forum | Dépôt | Espace kids
Back to top
View user's profile Send private message Visit poster's website 
dejan555


Joined: 30 Nov 2008
Posts: 2704
Location: Montenegro

PostPosted: Tue 21 Oct 2014, 16:52    Post subject:  

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.

Code:
13 root:960px$ data=$(exiv2 IMG_5834-960.JPG)
14 root:960px$ echo "$data" | grep "^Image size"
Image size      : 640 x 960


Code:
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


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.

_________________


Back to top
View user's profile Send private message Visit poster's website MSN Messenger 
slavvo67

Joined: 12 Oct 2012
Posts: 445
Location: The other Mr. 305

PostPosted: Tue 21 Oct 2014, 20:22    Post subject:  

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
Back to top
View user's profile Send private message 
trio


Joined: 21 Dec 2008
Posts: 1817
Location: अनुमोदना

PostPosted: Tue 21 Oct 2014, 22:07    Post subject:  

Thanks all for replying, I think I'm going to use eviv2 or SFR's script

Regards,

Trio

_________________
PET Maker|EasyLauncher
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7841
Location: qld

PostPosted: Wed 22 Oct 2014, 00:31    Post subject:  

You can try netpbm tools

Eg:
Code:
 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


There is also giftopnm, winicontoppm, ppmtogif, bmptoppm ..and so on.

http://netpbm.sourceforge.net


Working example, noisy on the console though
Code:
#!/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}'


_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
trio


Joined: 21 Dec 2008
Posts: 1817
Location: अनुमोदना

PostPosted: Wed 22 Oct 2014, 22:21    Post subject:  

Thanks bro

SFR's script with a little modification just fits my need

Regards,


Trio

_________________
PET Maker|EasyLauncher
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [10 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0734s ][ Queries: 12 (0.0038s) ][ GZIP on ]