Last active
August 6, 2019 23:09
-
-
Save garystafford/77f3242b4a8e8ffeb4df09ff3d3d3617 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 | |
# optimized for processing screen grabs | |
# copy and paste into GIMP Python Console | |
# open all images in Gimp to process | |
# script scales, sharpens, and exports all open images as PNGs | |
# Filters > Python-Fu > Console | |
import importlib | |
gimpfu_path = '/Applications/Gimp-2.10/Contents/Resources/lib/gimp/2.0/python/gimpfu.py' | |
gimpfu = importlib.load_source('module.name', gimpfu_path) | |
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) | |
# 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, compression): | |
images = gimp.image_list() | |
for image in images: # for all open files | |
print image.uri | |
scale_image(image, scale) # scale | |
export_png_file(image, compression) # compression | |
# 33% scaling with level 8 compression | |
process_images(.33, 8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment