#!/usr/bin/env python
# -*- coding: UTF8 -*-
# Copyright (C) 2008 by
#   Francisco Moreno Llorca
#   http://www.assamita.net
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

from os import listdir,system,popen4
try:
    import Image
except:
    print "No tienes ImageMagick para Python instalado, sorry....\n"
    print "You dont have installed ImageMagick for Python, sorry...\n"
    sys.exit(1)

listado = listdir('./')
for b in listado:
    extension = b.split(".")[-1]
    if extension == "avi" or extension == "mov" or extension == "mp4":
        print "Saltando "+ b + " por ser un vídeo. Skipping "+b+" , is a movie!"
    else:
        print "Procesando "+b + ". Processing...."
        try:
            a = Image.open(b)
            
            if a.size[0] > a.size[1]:
                system('convert '+b+' -quality 85 -resize 800x600 '+'s_'+b)
            else:
                system('convert '+b+' -quality 85 -resize 600x800 '+'s_'+b)
        except:
            print "Saltando "+ b + " por no ser una imagen. Skipping "+b+" , it is not a picture."
print "Terminado. Complete."

