added o for flipping originals. Added a tool for automating image description generation. Release 1.5
This commit is contained in:
127
Qalbum-descriptor.py
Executable file
127
Qalbum-descriptor.py
Executable file
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2012 Ville Rantanen
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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 Lesser 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys,os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from optparse import OptionParser
|
||||
from math import ceil
|
||||
|
||||
# (c) ville.rantanen@helsinki.fi
|
||||
|
||||
imagesearch=re.compile('.*\.jpg$|.*\.jpeg$|.*\.gif$|.*\.png$|.*\.svg$|.*\.pdf$',re.I)
|
||||
excludepaths=re.compile('_med|_tn|\..*')
|
||||
DESCFILE='descriptions.csv'
|
||||
|
||||
def getimagelist(path):
|
||||
''' Returns a list of images matching the regex '''
|
||||
list=os.listdir(path)
|
||||
imgs=[]
|
||||
for f in list:
|
||||
if (imagesearch.match(os.path.join(path,f))) and (os.path.isfile(os.path.join(path,f))):
|
||||
imgs.append(f)
|
||||
return imgs
|
||||
|
||||
def getpathlist(path):
|
||||
''' Returns a list of subfolders not matching the exclusion regex '''
|
||||
list=os.listdir(path)
|
||||
paths=[]
|
||||
for d in list:
|
||||
if (not excludepaths.match(d)) and (os.path.isdir(os.path.join(path,d))):
|
||||
paths.append(d)
|
||||
return paths
|
||||
|
||||
def createdesc(path,list):
|
||||
''' Runs imagemagick identify to create descriptions of images '''
|
||||
if len(list)==0:
|
||||
return
|
||||
if os.path.exists(os.path.join(path,DESCFILE)):
|
||||
if options.force:
|
||||
os.remove(os.path.join(path,DESCFILE))
|
||||
else:
|
||||
print('Descriptions exist, not overwriting.')
|
||||
return
|
||||
outfile=open(os.path.join(path,DESCFILE),'w')
|
||||
n=1
|
||||
nsum=len(list)
|
||||
for i in list:
|
||||
inpath=os.path.join(path,i)
|
||||
desc=create_description(inpath,options.format)
|
||||
outfile.write(i+"\t"+desc)
|
||||
outfile.flush()
|
||||
print('('+str(n)+'/'+str(nsum)+') '+i+"\t"+desc[0:-1])
|
||||
n+=1
|
||||
return
|
||||
|
||||
def create_description(infile,format):
|
||||
idargs=['identify','-format',format,infile+'[0]']
|
||||
idp=subprocess.Popen(idargs,stdout=subprocess.PIPE)
|
||||
output = idp.stdout.read()
|
||||
return output
|
||||
|
||||
def traverse(path):
|
||||
''' The recursive main function to create the thumbs and seek sub folders '''
|
||||
print(path)
|
||||
pathlist=getpathlist(path)
|
||||
imagelist=getimagelist(path)
|
||||
print(str(len(pathlist))+' paths')
|
||||
print(str(len(imagelist))+' images')
|
||||
createdesc(path,imagelist)
|
||||
if options.recursive:
|
||||
for p in pathlist:
|
||||
traverse(os.path.join(path,p))
|
||||
return
|
||||
|
||||
def execute():
|
||||
''' Main execution '''
|
||||
usage='''Usage: %prog [options] folder
|
||||
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 rewriting of descriptions")
|
||||
parser.add_option("--format",type="str",dest="format",default="",
|
||||
help="""Formatting string, see: http://www.imagemagick.org/script/escape.php.
|
||||
Setting this option will override the presets""")
|
||||
parser.add_option("-r",action="store_true",dest="recursive",default=False,
|
||||
help="Recurse in to subfolders")
|
||||
parser.add_option("-p",type="int",dest="preset",default=1,
|
||||
help="presets for descriptions. \"-p 0\" to get the list")
|
||||
global options
|
||||
(options,args)=parser.parse_args()
|
||||
if len(args) != 1 and options.preset!=0:
|
||||
parser.error("incorrect number of arguments")
|
||||
presets=[
|
||||
'%f: %[EXIF:DateTimeOriginal]',
|
||||
'%f: %wx%h %[size]',
|
||||
'%f<br/><i>%[EXIF:DateTimeOriginal] %[EXIF:ExposureTime]s F%[EXIF:FNumber]</i>']
|
||||
if options.preset<1:
|
||||
for row in range(len(presets)):
|
||||
print row+1," ",presets[row]
|
||||
sys.exit(0)
|
||||
if options.format=="":
|
||||
if options.preset>len(presets):
|
||||
parse.error("No such preset")
|
||||
options.format=presets[options.preset-1]
|
||||
|
||||
traverse(os.path.abspath(args[0]))
|
||||
return
|
||||
|
||||
execute()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
28
Qalbum.py
28
Qalbum.py
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2011 Ville Rantanen
|
||||
# Copyright 2012 Ville Rantanen
|
||||
#
|
||||
# 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
|
||||
@@ -26,7 +26,7 @@ from datetime import datetime
|
||||
|
||||
# (c) ville.rantanen@helsinki.fi
|
||||
|
||||
__version__='1.5b'
|
||||
__version__='1.5'
|
||||
|
||||
webfilesearch=re.compile('.*index.html$|.*gallerystyle.css$|.*galleryscript.js$|.*descriptions.csv$|\..*',re.I)
|
||||
imagesearch=re.compile('.*\.jpg$|.*\.jpeg$|.*\.gif$|.*\.png$|.*\.svg$|.*\.pdf$',re.I)
|
||||
@@ -50,6 +50,13 @@ def getheader(path,parent,title=""):
|
||||
</HEAD>
|
||||
<BODY>
|
||||
'''
|
||||
def getfooter():
|
||||
return '''
|
||||
<div id="footer">Generated with Qalbum '''+__version__+''' ('''+datetime.today().strftime("%y-%m-%d %H:%M")+''') <a href="http://code.google.com/p/qalbum/wiki/Usage" target="_TOP">Need help?</a></div>
|
||||
<script language="javascript">setup();</script>
|
||||
</BODY>
|
||||
</HTML>
|
||||
'''
|
||||
|
||||
def getimagelist(path):
|
||||
''' Returns a list of images matching the regex '''
|
||||
@@ -68,7 +75,7 @@ def getfiletimes(path,list):
|
||||
''' Returns a list of modification times '''
|
||||
times=[]
|
||||
for p in list:
|
||||
times.append(os.path.getmtime(os.path.join(path,p)))
|
||||
times.append(int(os.path.getmtime(os.path.join(path,p))))
|
||||
return times
|
||||
|
||||
def getnonimagelist(path):
|
||||
@@ -237,6 +244,7 @@ def getdescriptions(path,list):
|
||||
escapechar='\\',
|
||||
quoting=csv.QUOTE_NONE)
|
||||
for row in reader:
|
||||
if len(row)>1:
|
||||
if row[0] in list:
|
||||
i=list.index(stripquotes.sub('',row[0]))
|
||||
desc[i]=stripquotes.sub('',row[1])
|
||||
@@ -320,7 +328,7 @@ def traverse(path,crumbs):
|
||||
f.write(imagestring)
|
||||
f.write(filestring)
|
||||
f.write('<div id="listcontainer"></div>')
|
||||
f.write(footer)
|
||||
f.write(getfooter())
|
||||
f.close()
|
||||
createthumbs(path,imagelist)
|
||||
for p in pathlist:
|
||||
@@ -339,12 +347,6 @@ class AndurilOptions:
|
||||
self.attachments=True
|
||||
|
||||
def execute(cf):
|
||||
global footer
|
||||
footer='''
|
||||
<div id="footer">Generated with Anduril ('''+datetime.today().strftime("%y-%m-%d %H:%M")+''')</div>
|
||||
<script language="javascript">setup();</script>
|
||||
</BODY>
|
||||
</HTML>'''
|
||||
global inputs
|
||||
global options
|
||||
inputs=[]
|
||||
@@ -438,12 +440,6 @@ folder is the root folder of the image album.'''
|
||||
# Copy all resources to target folder
|
||||
shutil.copyfile(os.path.join(fullpath,'gallerystyle.css'),os.path.join(startpath,'gallerystyle.css'))
|
||||
shutil.copyfile(os.path.join(fullpath,'galleryscript.js'),os.path.join(startpath,'galleryscript.js'))
|
||||
global footer
|
||||
footer='''
|
||||
<div id="footer">Generated with Qalbum '''+__version__+''' ('''+datetime.today().strftime("%y-%m-%d %H:%M")+''') <a href="http://code.google.com/p/qalbum/wiki/Usage" target="_TOP">Need help?</a></div>
|
||||
<script language="javascript">setup();</script>
|
||||
</BODY>
|
||||
</HTML>'''
|
||||
global inputs
|
||||
inputs=[]
|
||||
inputs.append((None,'Gallery',None))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2011 Ville Rantanen
|
||||
Copyright 2012 Ville Rantanen
|
||||
|
||||
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
|
||||
@@ -548,7 +548,7 @@ function keypressed(e) {
|
||||
}
|
||||
// o: originals
|
||||
if (unicode==79) {
|
||||
fliporiginalsi();
|
||||
fliporiginals();
|
||||
}
|
||||
// f: fullscreen
|
||||
if (unicode==70) {
|
||||
|
||||
Reference in New Issue
Block a user