diff --git a/scripts/photofilmstrip-auto b/scripts/photofilmstrip-auto new file mode 100755 index 0000000..48c48bf --- /dev/null +++ b/scripts/photofilmstrip-auto @@ -0,0 +1,64 @@ +#!/usr/bin/python +# -*- coding: utf-8 +""" + Contributed by Yoandy S +""" +import argparse +import sys +import os +import glob +from photofilmstrip.CLI import main as photofilmstrip_cli +from photofilmstrip.core.Project import Project +from photofilmstrip.core.ProjectFile import ProjectFile +from photofilmstrip.core.Picture import Picture +from photofilmstrip.action.ActionAutoPath import ActionAutoPath + + +def make_project(path, project_path, duration, time_per_image): + project = Project() + images = [] + for picpath in glob.glob(path + '*.jpg') + glob.glob(path + '*.JPG'): + picture = Picture(picpath) + actAp = ActionAutoPath(picture, project.GetAspect()) + actAp.Execute() + images.append(picture) + if not duration: + duration = len(images) * time_per_image + project.SetDuration(duration) + project.SetPictures(images) + project_file = ProjectFile(project, project_path) + project_file.Save() + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Generate video from images in\ + a directory.') + parser.add_argument("directory_path", help="Path of directory with source\ + images.") + parser.add_argument("-d", "--destination-path", + help="Path where output files will be created.") + parser.add_argument("-u", "--duration", default=0, type=int, + help="Set the duration of the output Video.") + parser.add_argument("-x", "--time-per-image", default=10, type=int, + help="This is use to calculate the total time based on\ + the number of images.") + args = parser.parse_args() + if args.time_per_image and args.duration: + print("WARNING: The time-per-image Value is ignored.") + if not args.destination_path: + WD = os.path.join(args.directory_path, "output") + try: + if not os.path.exists(WD): + os.mkdir(WD) + except PermissionError: + print("Permission denied: error creating directory.") + path = os.path.normpath(args.directory_path) + '/' + project_name = 'photofilmstrip-prj-' + str(os.stat(path).st_ino) + '.pfs' + project_path = os.path.join(WD, project_name) + if os.path.exists(project_path): + print ("WARNING: Project file already exist, will be overwritten") + + make_project(path, project_path, args.duration, args.time_per_image) + sys.argv = [sys.argv[0]] +\ + '-p {} -o {} -t 2 -f 5'.format(project_path, WD).split() + photofilmstrip_cli() diff --git a/setup.py b/setup.py index 77c39d1..1de6d89 100644 --- a/setup.py +++ b/setup.py @@ -581,6 +581,9 @@ def Unzip(zipFile, targetDir, stripFolders=0): platform_scripts = [] platform_data = [] if os.name == "nt": + platform_scripts.append(os.path.join("windows", "photofilmstrip-auto.bat")) + platform_data.append(os.path.join("share", "doc", "photofilmstrip")) + platform_scripts.append(os.path.join("windows", "photofilmstrip.chm")) platform_scripts.append(os.path.join("windows", "photofilmstrip.bat")) platform_scripts.append(os.path.join("windows", "photofilmstrip-cli.bat")) else: @@ -686,6 +689,7 @@ def Unzip(zipFile, targetDir, stripFolders=0): scripts=[ "scripts/photofilmstrip", "scripts/photofilmstrip-cli", + "scripts/photofilmstrip-auto" ] + platform_scripts, name=Constants.APP_NAME.lower(), diff --git a/windows/photofilmstrip-auto.bat b/windows/photofilmstrip-auto.bat new file mode 100644 index 0000000..afc3732 --- /dev/null +++ b/windows/photofilmstrip-auto.bat @@ -0,0 +1,2 @@ +@"%~dp0..\python" "%~dp0photofilmstrip-auto" %* +