kurobyte

Image to WebP converter

Jan 12th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. ##Image to WebP converter v0.1 by Kurobyte
  2. ##Usage
  3. ##Download google compresion tool https://developers.google.com/speed/webp/download and unzip it
  4. ##place this script in the unziped folder, and drag'n drop images on it.
  5. import sys, os;
  6. from subprocess import call;
  7.  
  8. #Config#
  9. execPath = os.path.dirname(sys.argv[0]);
  10. compresion = 90; #Quality rate values between [0 , 100]# "-q", str(compresion),
  11. specificFolder = "\\webp"; #Leve it empty "" if you don't want to create a output dir for the images.
  12. validFormats = ['.png', '.jpg', '.jpeg'];
  13.  
  14.  
  15. def main(images):
  16.     for img in imatges:
  17.         path, extension = os.path.splitext(img);
  18.         path = os.path.dirname(img);
  19.         filename = (os.path.basename(img)).replace(extension, '');
  20.        
  21.         if extension.lower() in validFormats :
  22.             output = path+specificFolder;
  23.             if not (os.path.exists(output)):
  24.                 os.mkdir(output);
  25.  
  26.             call([execPath+"\\cwebp.exe", "-lossless", "-quiet", img,
  27.              "-o", output+"\\"+filename+".webp"],
  28.               shell=True);
  29.             print filename+" | Converted to '.webp'";
  30.         else:
  31.             print 'Image format not supported';
  32.  
  33.  
  34. imatges = [];
  35. for i in range(1, len(sys.argv)):
  36.     imatges.append(sys.argv[i]);
  37.  
  38. main(imatges);
  39. raw_input("Completed\r\nPres any key to continue.");
Advertisement
Add Comment
Please, Sign In to add comment