Reputation: 1004
Consider I have an image image.png
in a folder XYZ
. I need a Python script which asks the user to enter the image name and the output should be the image pixel and size.
I tried on terminal using sips
command as following:
sips -g pixelWidth -g pixelHeight image.png
I need to incorporate the same on Python. I tried with this code
import os
for rootpath,dir,file in os.walk("/Volumes/Macintosh HD/users/username/myfolder"):
for files in file:
def test(name):
return (os.system(sips -g pixelWidth -g pixelHeight name))
But this is not helpful. I am new to Python and doing some experiments. So any help/idea will be appreciated :)
Upvotes: 0
Views: 325
Reputation: 174624
Your logic should be:
Here's how to do that:
import os
from subprocess import Popen, PIPE
def run_command(user_input):
image_path = '/home/user/images/'
command_to_run = '/usr/bin/sips'
if not user_input:
return "You didn't enter anything!"
if not os.path.exists(image_page+user_input):
return "I cannot find that image!"
else:
output = Popen([command_to_run,
"-g", "PixelWidth",
"-g", "PixelHeight",
image_path+user_input], stdout=PIPE).communicate()[0]
return "The result is: ",output
user_input = raw_input("Please enter the image name: ")
print run_command(user_input)
Upvotes: 1