1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
24 def generate(filename
, external
=True):
26 process
= subprocess
.Popen(
35 stdout
=subprocess
.PIPE
,
36 stderr
=subprocess
.STDOUT
,
38 while process
.poll() is None:
39 process
.stdout
.read(1024) # empty buffer to be sure
42 return _thumbname(filename
)
44 return _internal(filename
)
46 def _thumbname(filename
):
47 root
= os
.path
.splitext(filename
)[0]
50 def _internal(filename
):
51 imagename
= os
.path
.split(filename
)[1]
52 thumbname
= _thumbname(filename
)
54 if os
.path
.exists(thumbname
):
58 scene
= bpy
.data
.scenes
[0] # FIXME, this is dodgy!
59 scene
.render
.image_settings
.file_format
= "JPEG"
60 scene
.render
.image_settings
.quality
= 90
62 # remove existing image, if there's a leftover (otherwise open changes the name)
63 if imagename
in bpy
.data
.images
:
64 img
= bpy
.data
.images
[imagename
]
65 bpy
.data
.images
.remove(img
)
67 bpy
.ops
.image
.open(filepath
=filename
)
68 img
= bpy
.data
.images
[imagename
]
70 img
.save_render(thumbname
, scene
=scene
)
73 bpy
.data
.images
.remove(img
)
76 process
= subprocess
.Popen(["convert", thumbname
, "-resize", "300x300", thumbname
])
79 except Exception as exp
:
80 print("Error while generating thumbnail")
85 if __name__
== "__main__":
87 start
= sys
.argv
.index("--") + 1
90 for filename
in sys
.argv
[start
:]:
91 generate(filename
, external
=False)