nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Script to Display Image size, Res, and Compression

This is a discussion on Script to Display Image size, Res, and Compression within the Shell scripting forums, part of the Development/Scripting category; Is there a script or command(s) that will allow me to view the following information, Image Size Image Resolution Image ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-02-2007, 04:07 AM
Junior Member
User
 
Join Date: Feb 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
TiredOrangeCat
Default Script to Display Image size, Res, and Compression

Is there a script or command(s) that will allow me to view the following information,

Image Size
Image Resolution
Image Compression

If its a simple command cool, if its a script can you please explain whats what and whys where.
Reply With Quote
  #2 (permalink)  
Old 10-02-2007, 01:55 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,707
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Welcome to nixCraft forum!

You can try identify command:
Code:
identify 2009.jpg
Output:
2009.jpg JPEG 1024x768 DirectClass 91kb 0.000u 0:01

For more info pass -verbose option to command:
Code:
identify -verbose networking.jpg
Output:
Code:
Format: JPEG (Joint Photographic Experts Group JFIF format)
  Geometry: 488x281
  Class: DirectClass
  Colorspace: RGB
  Type: TrueColor
  Depth: 8 bits
  Endianess: Undefined
  Channel depth:
    Red: 8-bits
    Green: 8-bits
    Blue: 8-bits
  Channel statistics:
    Red:
      Min: 0
      Max: 255
      Mean: 221.43
      Standard deviation: 69.9033
    Green:
      Min: 0
      Max: 255
      Mean: 228.501
      Standard deviation: 55.7455
    Blue:
      Min: 0
      Max: 255
      Mean: 238.427
      Standard deviation: 41.9074
  Colors: 24088
  Rendering-intent: Undefined
  Resolution: 72x72
  Units: Undefined
  Filesize: 22kb
  Interlace: None
  Background Color: grey100
  Border Color: #DFDFDF
  Matte Color: grey74
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Orientation: Undefined
  JPEG-Quality: 75
  JPEG-Colorspace: 2
  JPEG-Sampling-factors: 2x2,1x1,1x1
  signature: e50adabb6c5f76a4aa0caf8e28dbecf19bd46a19ecd230007387a6cc3a744038
  Tainted: False
  User Time: 0.010u
  Elapsed Time: 0:01
Here is a script:
Code:
#!/bin/bash
function die(){
 echo $@
 exit 1
}

# fallback
[ $# -eq 0 ] && die "Syntax: $0 image-file-name" || file=$1
IDEN=$(which identify)
[ $? -eq 1 ] && die "Command identify not found. Install imagemagick package" || :

# get data
size=$($IDEN -verbose $file | grep size | awk '{ print $2}')
resolution=$($IDEN -verbose $file | grep Resolution | awk '{ print $2}')
compression=$($IDEN -verbose $file | grep Compression | awk '{ print $2}' )

# display back
echo "Image name - $file"
echo "Image size - $size"
echo "Image resolution - $resolution"
echo "Image compression - $compression"
Read man page of identify command for more info and make sure package imagemagick is installed
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 12-02-2007, 12:04 AM
Junior Member
User
 
Join Date: Feb 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
TiredOrangeCat
Default

Thanks, thats just what I was lookin for. Now if I were to need to run this through an entire diecrtory of files would I need to toss it into a loop? I came up with something similar yesrturday while experimenting myself but I was having trouble printing the file name.

identify -verbose *.*|awk '/Geometry/{print($2)}'|awk -Fx '{print("*.* : "($1"x"$2))}'> /home/Main/resolution.txt
sort -n /home/Main/resolution.txt > /home/Main/sortres.txt
grep 835 /home/Main/sortres.txt > /home/Main/finalsort.txt


Ignore the redundancy its a nessceary evil. I used *.* to catch all the files inside the diectory but found I cannot print what the current file is. Is there another way I can catch all files and print the name of the appropriate file with its res?
Reply With Quote
  #4 (permalink)  
Old 12-02-2007, 10:27 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,707
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

I am not sure what you are doing but correct way to read file one by one is using for loop
Code:
for f in /path/to/*
do
   echo $f
done
$f holds each file name and
Code:
for f in /path/to/*
do
identify -verbose $f |awk '/Geometry/{print($2)}'|awk -Fx '{print("*.* : "($1"x"$2))}'>> /home/Main/resolution.txt 
done
HTH
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #5 (permalink)  
Old 12-02-2007, 11:04 PM
Junior Member
User
 
Join Date: Feb 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
TiredOrangeCat
Default

Im pretty new to this UNIX programming stuff and was just setting up a few scripts for myself, to see if I could create a few utilities to retrieve specific information from images. Thanks. Mostly right now its kinda like smashing two rocks together for me I get the code out there but its far from sophisticated or stable. lol, oh well back to the drawing board. I really appreciate the help.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Mount iso image saurabh_jsh Linux hardware 1 29-04-2008 02:52 PM
Script to display number of lines and words from a file newbewie Shell scripting 2 07-12-2007 10:37 PM
How to increase the vmalloc size? warren Linux software 1 11-09-2006 12:59 PM
Linux command to check size of hard drive disk gbdood Linux software 2 27-08-2006 09:44 AM
moving files based on size kavi Shell scripting 2 11-11-2005 05:17 PM


All times are GMT +5.5. The time now is 08:56 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38