Last active
July 10, 2020 22:03
-
-
Save garystafford/5259576a7e9299d5b80284489aa25fc3 to your computer and use it in GitHub Desktop.
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/python | |
# copy and paste into GIMP Python Console | |
# scales, sharpens, strokes, and exports all open images as PNGs | |
# optimized for processing screen grabs | |
# Filters > Python-Fu > Console | |
# pip install importlib | |
import importlib | |
#gimpfu_path = '/Applications/Gimp-2.10/Contents/Resources/lib/gimp/2.0/python/gimpfu.py' | |
##gimpfu_path = '/Applications/GIMP.app/Contents/Resources/lib/gimp/2.0/python/gimpfu.py' | |
#gimpfu = importlib.load_source('module.name', gimpfu_path) | |
# Scale screen-grab and add border | |
def stroke_image(image, brush_size): | |
width = image.width | |
height = image.height | |
brush_diameter = brush_size | |
pdb.gimp_context_set_brush("2. Hardness 050") | |
pdb.gimp_context_set_brush_size(brush_diameter) | |
pdb.gimp_context_set_foreground("#555555") | |
drawable = pdb.gimp_image_active_drawable(image) | |
pdb.gimp_image_select_rectangle(image, 0, 0, 0, (width - 1), (height - 1)) | |
pdb.gimp_edit_stroke(drawable) | |
def scale_image(image, scale): | |
width = image.width | |
height = image.height | |
scale = 1.0 / scale # 1.0/.50 = 2 or 50% | |
drawable = pdb.gimp_image_active_drawable(image) | |
pdb.gimp_context_set_interpolation(INTERPOLATION_CUBIC) | |
pdb.gimp_image_scale(image, width / scale, height / scale) | |
pdb.plug_in_unsharp_mask(image, drawable, 1.0, 0.25, 0) | |
pdb.gimp_context_set_background("#ffffff") | |
pdb.gimp_image_flatten(image) | |
def export_png_file(image, compression): | |
drawable = pdb.gimp_image_active_drawable(image) | |
# pdb.file_png_save2(image, drawable, image, image, | |
# interlace, compression, bkgd, gama, offs, phys, time, comment, svtrans) | |
pdb.file_png_save2(image, drawable, image.uri.strip('file:\\\\'), | |
image.name, 0, compression, 0, 0, 0, 0, 0, 0, 0) | |
def process_images(scale, brush_size, compression): | |
images = gimp.image_list() | |
for image in images: # all open files | |
print image.uri | |
scale_image(image, scale) # scale | |
stroke_image(image, brush_size) # brush size | |
export_png_file(image, compression) # compression | |
process_images(.33, 2, 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment