Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##Image to WebP converter v0.1 by Kurobyte
- ##Usage
- ##Download google compresion tool https://developers.google.com/speed/webp/download and unzip it
- ##place this script in the unziped folder, and drag'n drop images on it.
- import sys, os;
- from subprocess import call;
- #Config#
- execPath = os.path.dirname(sys.argv[0]);
- compresion = 90; #Quality rate values between [0 , 100]# "-q", str(compresion),
- specificFolder = "\\webp"; #Leve it empty "" if you don't want to create a output dir for the images.
- validFormats = ['.png', '.jpg', '.jpeg'];
- def main(images):
- for img in imatges:
- path, extension = os.path.splitext(img);
- path = os.path.dirname(img);
- filename = (os.path.basename(img)).replace(extension, '');
- if extension.lower() in validFormats :
- output = path+specificFolder;
- if not (os.path.exists(output)):
- os.mkdir(output);
- call([execPath+"\\cwebp.exe", "-lossless", "-quiet", img,
- "-o", output+"\\"+filename+".webp"],
- shell=True);
- print filename+" | Converted to '.webp'";
- else:
- print 'Image format not supported';
- imatges = [];
- for i in range(1, len(sys.argv)):
- imatges.append(sys.argv[i]);
- main(imatges);
- raw_input("Completed\r\nPres any key to continue.");
Advertisement
Add Comment
Please, Sign In to add comment