Linux / UNIX Tech Support Forum
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 ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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. |
| Sponsored Links | ||
|
|
|
||||
|
Welcome to nixCraft forum!
You can try identify command: Code:
identify 2009.jpg 2009.jpg JPEG 1024x768 DirectClass 91kb 0.000u 0:01 For more info pass -verbose option to command: Code:
identify -verbose networking.jpg 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
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"
__________________
Vivek Gite Linux Evangelist |
|
|||
|
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? |
|
||||
|
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 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
__________________
Vivek Gite Linux Evangelist |
|
|||
|
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
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| 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 |