Gimp/build/windows/installer/splash2installer.py
Jehan 2fd25fe6bd build: generate the Windows installer welcome images from the splash screen.
After discussion with Jernej, InnoSetup should now work better with rescaling
a big image properly to the window size, yet the ratio should still matter.
Apparently the welcome image is a hack and this is why it requires specific
ratio images. We don't use the big size yet, but since Jernej told me which
dimensions are expected, I already added the code for it to make it easier
later.

So anyway this code would allow us not to have to commit welcome images each
time, which are basically resized copy in BMP of the splash screen, slowly yet
surely filling up our repository with image duplicates.
After all, we develop a scriptable image editor! We should use it to edit images
and export in expected formats!

I only use this script for the devel installer for now, for testing and see how
it goes.
2023-06-27 00:39:17 +02:00

38 lines
1.6 KiB
Python

image = Gimp.list_images()[0]
config = Gimp.get_pdb().lookup_procedure("file-bmp-save").create_config()
def export_scaled_img(image, target_width, target_height, export_path):
img = image.duplicate()
w = img.get_width()
h = img.get_height()
new_width = target_width
new_height = target_height
offx = 0
offy = 0
if w / target_width * target_height < h:
new_width = target_height / h * w
offx = (target_width - new_width) / 2
else:
new_height = target_width / w * h
offy = (target_height - new_height) / 2
img.scale(new_width, new_height)
img.resize(target_width, target_height, offx, offy)
# XXX: should we rather use the average color as border?
black = Gimp.RGB()
black.set(0, 0, 0)
Gimp.context_set_background(black)
drawables = img.list_selected_drawables()
for d in drawables:
d.resize_to_image_size()
config.set_property("image", img)
config.set_property("num-drawables", len(drawables))
config.set_property("drawables", Gimp.ObjectArray.new(Gimp.Drawable, drawables, False))
config.set_property("file", Gio.file_new_for_path(export_path))
Gimp.get_pdb().run_procedure_config("file-bmp-save", config)
# These sizes are pretty much hardcoded, and in particular the ratio matters in
# InnoSetup. Or so am I told. XXX
export_scaled_img(image, 994, 692, 'build/windows/installer/installsplash-devel.bmp')
export_scaled_img(image, 497, 360, 'build/windows/installer/installsplash_small-devel.bmp')
export_scaled_img(image, 1160, 803, 'build/windows/installer/installsplash_big-devel.bmp')