The AppleScript scripting dictionary for Keynote may harbor complexities that would make your goal of scripted automation either difficult to support or even implement. What I suggest you do is create one or two Keynote templates.
You make one template (aka Theme) with room for four pictures across, and the second Theme with two rows of four pictures. Save each as Keynote Themes from File menu > Save Theme… > Add to Theme Chooser.
Visit Keynote > Settings > Rulers and make these settings:
Close that panel and from the Keynote View menu > Show Rulers.
Begin by dragging/dropping an arbitrary image that you would normally use on to the Keynote slide. From the Keynote arrange panel, you set its initial position, height, and width to your specs. Next, you visit the Format menu > Advanced > Define as Media Placeholder. This means that when you reuse this template in the future, you can just drag/drop a new image on to that placeholder it will automatically become the replacement image.
Now, press the option key, click and drag the first Media Placeholder to your right with a 20 pt gap. The settings from that Ruler panel will provide automatic guides and measurements to assist you. Then, repeat this duplication effort for the next two media placeholder locations. For numbering, you will select a rectangular or circular shape from the Shape tool, double-click within it, and enter the centered number in it. Scale to need. Your choice of the background color for the shape and foreground color of the number text. You will need to place these numbered media items above the media placeholder as placing them within the media placeholder will prevent image replacement in future usage.
With your mouse, drag an imaginary box around your four images and numbered shapes to select them. On the Arrange panel, select group. Save this new Theme per above with a unique theme name.
Now, with this Keynote document remaining open, you will make the 8-image theme. Press the option key and click once on the 4-image group and simply drag downward to copy it. The automatic guides will help you. With the second row still selected, visit the Arrange panel and select Ungroup. Edit the number Shapes for 5 - 8, select all of the second row again, and from the Arrange panel, choose Group again.
Then, you will select File menu > Save Theme… and Add to Theme Chooser, but this time with a new name indicating 8-images.
In the future, you select which of these Themes you need and then drag and drop your new images over their respective placeholder media target. Dragging and dropping 4 - 8 images onto the appropriate Keynote slide should be more beneficial to your productive time than what you have now.