Add script to make wallpaper from image
This commit is contained in:
		
							parent
							
								
									4e2309831d
								
							
						
					
					
						commit
						7213ec13d4
					
				
					 1 changed files with 94 additions and 0 deletions
				
			
		
							
								
								
									
										94
									
								
								create_wallpaper.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								create_wallpaper.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,94 @@ | |||
| #!/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 | ||||
|     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 - picX * scale) // 2) | ||||
|         y0 = int((resY - picY * 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: | ||||
|             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 | ||||
| 
 | ||||
|     # save | ||||
|     pdb.gimp_file_save(GIMP_RUN_NONINTERACTIVE, img, img, 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", | ||||
| 	"<Toolbox>/File/Create/Wallpaper" | ||||
| 	"RGB*", | ||||
| 	[ | ||||
|     (PF_SPINNER, "resX", _("Screen width"), 2560), | ||||
|     (PF_SPINNER, "resY", _("Screen height"), 1440), | ||||
|     (PF_FILE, "sourceFile", _("Source file"), None), | ||||
|     (PF_STRING,  "targetFile", _("Desired target path"), "/home/sarah/sync/private/pictures_converted/bandori_0001.jpg") | ||||
|     ], | ||||
|     [], | ||||
| 	python_fu_make_wallpaper) | ||||
| 
 | ||||
| main() | ||||
		Loading…
	
	Add table
		
		Reference in a new issue