Skip to content

Instantly share code, notes, and snippets.

@rezkam
Last active September 6, 2017 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rezkam/8029485 to your computer and use it in GitHub Desktop.
Save rezkam/8029485 to your computer and use it in GitHub Desktop.
Dirtiest Code in Islam World (کثیف ترین کد جهان اسلام) -- Simple tool to resize images with intact aspect ratio - dciw.py
'''
Created on Sep 15, 2013
@author: Mohammad reza Kamalifard
usage :
python dciw.py imagename
'''
import Image
import sys
im = Image.open(sys.argv[1])
hSize, wSize = im.size
print 'Size of your image height is %d and width is %d'% (hSize, wSize)
print 'You can change Your image size with changing height of your photo and width is change automaticlly to maintain its aspect ratio?'
newHeight = float(raw_input('Please enter new height : '))
newWidth = wSize / (hSize / newHeight)
print newHeight, newWidth
answer = raw_input('This operation will replace and modify your image ! Do you want to change size? (Y, N) \n')
if answer.lower() == 'y':
im = im.resize((int(newHeight), int(newWidth)))
index = sys.argv[1].lower().find('.jpg')
file_name = sys.argv[1][:index]
im.save(file_name + 'resized.jpg')
elif answer.lower() == 'n':
sys.exit()
else:
print 'Please enter Y or N!'
@ShalbafZadeh
Copy link

Jaahnee Eslam)
must be Jahane Eslam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment