This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrws-02-genSidebarImage.py
executable file
·65 lines (55 loc) · 2.39 KB
/
rws-02-genSidebarImage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
#
# File = rws-genSidebarImage.py
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the MIT license.
#
# 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.
#
############################################################################
#
from gimpfu import *
import os
def gen_sidebar_image(inputImage, inputDrawable, tgtPath):
inputFileList = os.listdir(tgtPath)
srcFileList = []
# Get the list of all .jpg files in the source directory
for filename in inputFileList:
filename = filename.lower()
if filename.count('.jpg') > 0:
srcFileList.append(filename)
srcFileList = reversed(sorted(srcFileList))
for srcFile in srcFileList:
sidebarFilename = "sidebar-img.jpg"
# Open the .jpg image
srcFile = os.path.join(tgtPath, srcFile)
theImage = pdb.file_jpeg_load(srcFile, srcFile)
theLayer = theImage.active_layer
aspectRatio = float(theLayer.height) / theLayer.width
sidebarFile = os.path.join(tgtPath, sidebarFilename)
targetHeight = 500
targetWidth = int(round(targetHeight/aspectRatio))
theLayer.scale(targetWidth, targetHeight)
theImage.resize(targetWidth, targetHeight, 0, 0)
pdb.file_jpeg_save(theImage, theLayer, sidebarFile, sidebarFile, 0.9, 0, 0, 0, "", 0, 0, 0, 0)
pdb.gimp_image_delete(theImage)
break
############################################################################
register (
"python_fu_gen_sidebar_image", # Name registered in Procedure Browser
"Create sidebar image", # Widget title
"Create sidebar image", # Help
"[email protected]", # Author
"[email protected]", # Copyright Holder
"Feb 2019", # Date
"<Image>/Reddit/2 - Generate Sidebar Image", # Menu Location
"", # Image Type - No image required
[ ( PF_DIRNAME, "tgtPath", "Working Directory:", "" ), ], # Params
[], # Results
gen_sidebar_image, # Matches to name of function being defined
) # End register
main()