Created
May 6, 2016 23:53
-
-
Save olegch/ac2189f3fd3437b01c637d5898ba210e to your computer and use it in GitHub Desktop.
Batch split of multiple image files in half in GIMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import math | |
from gimpfu import * | |
import os | |
import re | |
import sys | |
sys.stderr = open('C:/Temp/python-fu-output.txt','a') | |
sys.stdout=sys.stderr | |
def python_oc_cut(srcPath, tgtPath): | |
open_images, image_ids = pdb.gimp_image_list() | |
if open_images > 0: | |
pdb.gimp_message ("Close open Images & Rerun") | |
else: | |
print 'start '+srcPath+' '+tgtPath | |
# list all of the files in source & target directories | |
allFileList = os.listdir(srcPath) | |
print allFileList | |
xform = re.compile('\.jpg', re.IGNORECASE) | |
# Find all of the jpeg files in the list & make xcf file names | |
# Dictionary - source & target file names | |
# Loop on jpegs, open each & save as xcf | |
print '1' | |
for srcFile in allFileList: | |
srcFileLow = srcFile.lower() | |
if srcFileLow.count('.jpg') > 0: | |
# Don't overwrite existing, might be work in Progress | |
srcFile = os.path.join(srcPath, srcFile) | |
print srcFile | |
image = pdb.file_jpeg_load(srcFile, srcFile) | |
# os.path.join inserts the right kind of file separator | |
drawable = image.active_drawable | |
pdb.script_fu_guides_remove(image, drawable) | |
pdb.script_fu_guide_new_percent(image, drawable, 1, 50) | |
pdb.plug_in_guillotine(image, drawable) | |
img0 = gimp.image_list()[0] | |
img1 = gimp.image_list()[1] | |
trgFile1 = os.path.join(tgtPath, img0.name) | |
trgFile2 = os.path.join(tgtPath, img1.name) | |
pdb.file_jpeg_save(img0, img0.active_drawable, trgFile1, trgFile1, 0.9, 0, 0, 0, "", 0, 0, 0, 0) | |
pdb.file_jpeg_save(img1, img1.active_drawable, trgFile2, trgFile2, 0.9, 0, 0, 0, "", 0, 0, 0, 0) | |
pdb.gimp_image_delete(img0) | |
pdb.gimp_image_delete(img1) | |
register( | |
"oc_cut", | |
"Cut images", | |
"Cut images", | |
"Oleg Chunikhin", | |
"Oleg Chunikhin", | |
"2016", | |
"OC _Cut Image...", | |
"", | |
[ | |
( PF_DIRNAME, "srcPath", "JPG Originals (source) Directory:", " " ), | |
( PF_DIRNAME, "tgtPath", "JPG Cut (target) Directory:", " " ), | |
], | |
[], | |
python_oc_cut, | |
menu = "<Image>/OC _Cut") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment