diff --git a/Qalbum-thumbnailer.py b/Qalbum-thumbnailer.py index fe1e2f4..7e47321 100755 --- a/Qalbum-thumbnailer.py +++ b/Qalbum-thumbnailer.py @@ -2,7 +2,7 @@ # # Copyright 2011 Ville Rantanen # -# This program is free software: you can redistribute it and/or modify it +# 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 3 of the License, or # (at your option) any later version. @@ -73,25 +73,42 @@ def createthumbs(path,list): r=str(options.width) res=r+'x'+r+'>' for i in list: - if (vectorsearch.match(i)): - if (options.force) or (not os.path.exists(os.path.join(path,'_med','med_'+i+'.jpg'))): - print('Medium.. '+i+' '+str(n)+'/'+str(nsum)) - convargs=['convert','-density','300x300',os.path.join(path,i)+'[0]','-background','white','-flatten','-resize',res,'-quality','97',os.path.join(path,'_med','med_'+i+'.jpg')] - convp=subprocess.call(convargs) - if (options.force) or (not os.path.exists(os.path.join(path,'_tn','tn_'+i+'.jpg'))): - convargs=['convert','-density','300x300',os.path.join(path,'_med','med_'+i+'.jpg'),'-background','white','-flatten','-thumbnail','90x90^','-gravity','Center','-crop','90x90+0+0','+repage','-quality','75',os.path.join(path,'_tn','tn_'+i+'.jpg')] - convp=subprocess.call(convargs) - else: - if (options.force) or (not os.path.exists(os.path.join(path,'_med','med_'+i+'.jpg'))): - print('Medium.. '+i+' '+str(n)+'/'+str(nsum)) - convargs=['convert','-define','jpeg:size='+r+'x'+r,os.path.join(path,i)+'[0]','-background','white','-flatten','-resize',res,'-quality','85',os.path.join(path,'_med','med_'+i+'.jpg')] - convp=subprocess.call(convargs) - if (options.force) or (not os.path.exists(os.path.join(path,'_tn','tn_'+i+'.jpg'))): - convargs=['convert','-define','jpeg:size=300x300',os.path.join(path,'_med','med_'+i+'.jpg'),'-background','white','-flatten','-thumbnail','90x90^','-gravity','Center','-crop','90x90+0+0','+repage','-quality','75',os.path.join(path,'_tn','tn_'+i+'.jpg')] - convp=subprocess.call(convargs) + outmedium=os.path.join(path,'_med','med_'+i+'.jpg') + outthumb=os.path.join(path,'_tn','tn_'+i+'.jpg') + inpath=os.path.join(path,i) + if (options.force) and os.path.exists(outmedium): + os.unlink(outmedium) + if (options.force) and os.path.exists(outthumb): + os.unlink(outthumb) + if (not os.path.exists(outmedium)): + print('Medium.. '+i+' '+str(n)+'/'+str(nsum)) + create_medium_bitmap(inpath,outmedium,r,link=options.link,vector=vectorsearch.match(i)) + if (not os.path.exists(outthumb)): + print('Thumbnail.. '+i+' '+str(n)+'/'+str(nsum)) + create_thumb_bitmap(outmedium,outthumb,vector=vectorsearch.match(i)) n+=1 return +def create_medium_bitmap(infile,outfile,r,link=False,vector=False): + if link: + os.symlink(infile,outfile) + return + res=r+'x'+r+'>' + if vector: + convargs=['convert','-density','300x300',infile+'[0]','-background','white','-flatten','-resize',res,'-quality','97',outfile] + else: + convargs=['convert','-define','jpeg:size='+r+'x'+r,infile+'[0]','-background','white','-flatten','-resize',res,'-quality','85',outfile] + convp=subprocess.call(convargs) + return + +def create_thumb_bitmap(infile,outfile,vector=False): + if vector: + convargs=['convert','-density','300x300',infile,'-background','white','-flatten','-thumbnail','90x90^','-gravity','Center','-crop','90x90+0+0','+repage','-quality','75',outfile] + else: + convargs=['convert','-define','jpeg:size=300x300',infile,'-background','white','-flatten','-thumbnail','90x90^','-gravity','Center','-crop','90x90+0+0','+repage','-quality','75',outfile] + convp=subprocess.call(convargs) + return + def cleanthumbs(path): ''' clears _med and _tn for unused thumbs ''' print('clearing unused thumbs...') @@ -135,9 +152,11 @@ def execute(): folder is the root folder of the image album.''' parser=OptionParser(usage=usage) parser.add_option("-f",action="store_true",dest="force",default=False, - help="Force regeneration of thumbnails") + help="Force regeneration of thumbnails and medium sized") parser.add_option("-c",action="store_true",dest="clean",default=False, help="Clean unused thumbnails") + parser.add_option("-l",action="store_true",dest="link",default=False, + help="Create symbolic link as medium size image instead of downscaling one.") parser.add_option("-r",action="store_true",dest="recursive",default=False, help="Recurse in to subfolders") parser.add_option("-w",type="int",dest="width",default=850,