#!/usr/bin/env python # make_wallpaper.py # Scales picture to fit wallpaper and adds matching background # # License: GPLv3 # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY# without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # To view a copy of the GNU General Public License # visit: http://www.gnu.org/licenses/gpl.html # # # ------------ #| Change Log | # ------------ # Rel 1: Initial release. from gimpfu import * def python_fu_make_wallpaper(resX, resY, sourceFile, targetFile) : # create new image in resolution size resX = int(resX) resY = int(resY) img = gimp.Image(resX, resY) bg = img.new_layer("bg", resX, resY) pic = pdb.gimp_file_load_layer(img, sourceFile) img.add_layer(pic, 0) # scale picture down if it's too big for resolution if pic.width > resX or pic.height > resY: scaleX = (resX - 50.0) / pic.width scaleY = (resY - 50.0) / pic.height scale = min(scaleX, scaleY) x0 = int((resX - pic.width * scale) // 2) y0 = int((resY - pic.height * scale) // 2) x1 = resX - x0 y1 = resY - y0 pic.scale(x0, y0, x1, y1) pic.set_offsets((resX-pic.width)/2,(resY-pic.height)/2) # get border average of image for 20px, 4 colors if not(pic.width == resX and pic.height == resY): color, _ = pdb.plug_in_borderaverage(img, pic, 20, 4) pdb.gimp_palette_set_foreground(color) # fill bg layer with calculated average bg.fill(FOREGROUND_FILL) # desature for certain bgcolors colorHSV = color.to_hsv() if colorHSV[1] > 50 and colorHSV[2] > 50: merged = img.merge_visible_layers(FALSE) img.add_layer(pdb.gimp_layer_copy(merged, FALSE)) multi = img.layers[0] multi.name = "multi" pdb.gimp_desaturate(multi) multi.opacity = 15.0 multi.mode = MULTIPLY_MODE img.add_layer(pdb.gimp_layer_copy(multi, FALSE)) sat = img.layers[0] sat.name = "sat" sat.mode = SATURATION_MODE final = img.merge_visible_layers(FALSE) # save pdb.gimp_file_save(img, final, targetFile, targetFile) register( "python_fu_make_wallpaper", "Scale picture and add background for wallpaper", "Scales picture to fit wallpaper and adds matching background", "Sarah Ziesel", "Sarah Ziesel", "April 2020", "/Python-Fu/Make Wallpaper...", "", [ (PF_SPINNER, "resX", "Screen width", 2560, (1, 9999, 1)), (PF_SPINNER, "resY", "Screen height", 1440, (1, 9999, 1)), (PF_FILE, "sourceFile", "Source file", "/home/sarah/sync/private/pictures/bandori/toxxtu77dsm41.jpg"), (PF_STRING, "targetFileName", "Desired target path", "/home/sarah/sync/private/pictures_converted") ], [], python_fu_make_wallpaper) main()