#!/usr/bin/env python # -*- coding: utf8 -*- # # Copyright (C) 2018 Niccolo Rigacci # # Plug-in for the GIMP: decor the image with a rounded border # and a drop shadow effect. It resizes the longest side of # the picture to the required size. # # Copy this Script-Fu script into $HOME/.gimp-X.Y/plug-ins/ directory, # it will appear under the "Tools", "Selection Tools" menu. from gimpfu import * def add_photo_border(img, drawable, max_size): # Scale the longest side to max_size img_width = pdb.gimp_image_width(img) img_height = pdb.gimp_image_height(img) # Resize the major side to the requested value if img_width >= img_height: new_width = max_size new_height = int(new_width * (float(img_height) / float(img_width))) else: new_height = max_size new_width = int(new_height * (float(img_width) / float(img_height))) pdb.gimp_image_scale(img, new_width, new_height) # Filters, Decor, Round Corners edge_radius = int(max_size * 0.025) # It is 20px for a 800px image add_drop_shadow = False shadow_x = shadow_y = blur = 0 background = True on_copy = False pdb.script_fu_round_corners(img, drawable, edge_radius, add_drop_shadow, shadow_x, shadow_y, blur, background, on_copy) # Flatten image drawable2 = pdb.gimp_image_flatten(img) # Filters, Decor, Add Border border_size = int(max_size * 0.020) # It is 16px for a 800px image x_size = y_size = border_size delta_value = 1 color = (255, 255, 255) pdb.script_fu_addborder(img, drawable2, x_size, y_size, color, delta_value) # Flatten image drawable3 = pdb.gimp_image_flatten(img) # Filters, Decor, Round Corners edge_radius = int(max_size * 0.030) # It is 24px for a 800px image add_drop_shadow = True shadow_x = shadow_y = int(edge_radius / 2) blur = edge_radius background = False on_copy = False pdb.script_fu_round_corners(img, drawable3, edge_radius, add_drop_shadow, shadow_x, shadow_y, blur, background, on_copy) # Merge Visible Layers pdb.gimp_image_merge_visible_layers(img, 0) register( "add-photo-border", "Decor the image with a rounded border and drop shadow.", "Decor the image with a rounded border and drop shadow.", "Niccolo Rigacci ", "Niccolo Rigacci - GPL v.3", "2018-05-24", "/Tools/Selection Tools/Add Rounded Border to Photo", "*", [ (PF_SLIDER, "max_size", "Scale the longest side to (px):", 800, (600, 1600, 16)) ], [], add_photo_border ) main()