eyeqube
asked on
query image dimension
Hi,
I need to query image file dimension. How is it possible if i have to use python. Alternatively any other way. If not possible with python.
dimension, genre, camera model, file version, product version, product name are attributes that appear in windows explorer right click.
Brgds,
kNish
I need to query image file dimension. How is it possible if i have to use python. Alternatively any other way. If not possible with python.
dimension, genre, camera model, file version, product version, product name are attributes that appear in windows explorer right click.
Brgds,
kNish
ASKER
true, imagemagick does it. My question is how do i query the dimension value....
ASKER
specifically, my question is as i mentioned first....how do i query attributes to a file in windows explorer
I do not have the PythonMagick installed (i.e. the Python wrapper around ImageMagick), so I cannot try that. However, the plain ImageMagick command line utilities are fine for that. Let's start with the dimension.
You want to use the 'identify' utility. It can be also used for setting the values. However, you should focus on the -format option. This one is used for extracting the info from the image. See the snippet below. It accepts one command-line argument -- the filename. Save
it to, say, imgattr.py.
In Windows Explorer, just drag the image over the icon of the script. It will show the cmd console window with the dimensions and then it asks you to press Enter.
This is only to get the idea. Of course, it is possible to extract the information into a variable.
You want to use the 'identify' utility. It can be also used for setting the values. However, you should focus on the -format option. This one is used for extracting the info from the image. See the snippet below. It accepts one command-line argument -- the filename. Save
it to, say, imgattr.py.
In Windows Explorer, just drag the image over the icon of the script. It will show the cmd console window with the dimensions and then it asks you to press Enter.
This is only to get the idea. Of course, it is possible to extract the information into a variable.
import subprocess
import sys
fname = sys.argv[1]
subprocess.call('identify -format "%w x %h" ' + fname )
raw_input('\n\n\nEnter...')
Here is the example how to get the string data into a variable.
import subprocess
import sys
fname = sys.argv[1] # get the argument = image file name
# Redirect the standard output of the 'identify' to the pipe
pipe = subprocess.Popen('identify -format "%w x %h" ' + fname,
stdout=subprocess.PIPE).stdout
s = pipe.read() # read the data from the pipe
# (the above produces one line, but could be more)
s = s.rstrip() # strip the line ending
print repr(s) # use the variable with the dimensions
Here is some more complex example that shows some EXIF information. It displays the following for one of my images
C:\tmp\_Python\eyeqube>img attr.py IMG.JPG
width: 3264
height: 2448
Model: Canon PowerShot A590 IS
Date: 2009:05:03 11:39:42
C:\tmp\_Python\eyeqube>img
width: 3264
height: 2448
Model: Canon PowerShot A590 IS
Date: 2009:05:03 11:39:42
import subprocess
import sys
fname = sys.argv[1] # get the argument = image file name
# Build the command to get the info
format = 'width:\t%w\nheight:\t%h\nModel:\t%[EXIF:Model]\nDate:\t%[EXIF:DateTime]'
cmd = 'identify -format "%s" %s' % (format, fname)
# Redirect the standard output of the 'identify' to the pipe
pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout
# Display the data from the pipe
for line in pipe:
sys.stdout.write(line)
ASKER
Hi,
Thank you for sharing thus far. Do you have pythonmagick for windows. I googled it but there is no straight answer for it.
Thank you for sharing thus far. Do you have pythonmagick for windows. I googled it but there is no straight answer for it.
No, I do not use PythonMagick for Windows. If I recall correctly, there is no binary ready for Windows and I was too lazy to prepare it ;) Anyway, I do use ImageMagic for automatic conversion of images for our documentation. Calling the command-line utilities (via scripts) works just fine for me and I had no need to invest my time into building PythonMagick binaries.
ASKER
Hi,
Thank you for sharing. in that case what command will help query the size of an image, using the utility imconvert. I fail to see a query option in this utility
Thank you for sharing. in that case what command will help query the size of an image, using the utility imconvert. I fail to see a query option in this utility
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your help. At present I am using the MImage class of maya to get the width and height. I would need a general solution i.e. something which i can run not only in maya(3d software) but also from windows.
http://www.imagemagick.org/script/index.php