Add new images to top of existing gallery not bottom

Here’s a version of the linked solution that overrides galleryAddToolbar to have an extra button (insertTop) to do what you want (in your “functions.php”):

add_filter( 'media_view_strings', function ( $strings, $post ) {
    $strings['addToGallery'] = __( 'Add to end of gallery' );
    $strings['addToGalleryTop'] = __( 'Add to start of gallery' );
    return $strings;
}, 10, 2 );

add_action( 'admin_footer' , function () {
    ?>
    <script>
    jQuery(document).ready(function() {
        (function ($) {
            if (typeof wp.media !== 'undefined') {
                wp.media.view.MediaFrame.Post.prototype.galleryAddToolbar = function () {
                    var media = wp.media, l10n = media.view.l10n;
                    this.toolbar.set( new media.view.Toolbar({
                        controller: this,
                        items: {
                            insert: {
                                style:    'secondary',
                                text:     l10n.addToGallery,
                                priority: 70,
                                requires: { selection: true },

                                /**
                                 * @fires wp.media.controller.State#reset
                                 */
                                click: function() {
                                    var controller = this.controller,
                                        state = controller.state(),
                                        edit = controller.state('gallery-edit');

                                    edit.get('library').add( state.get('selection').models );
                                    state.trigger('reset');
                                    controller.setState('gallery-edit');
                                }
                            },
                            insertTop: {
                                style:    'primary',
                                text:     l10n.addToGalleryTop,
                                priority: 80,
                                requires: { selection: true },

                                /**
                                 * @fires wp.media.controller.State#reset
                                 */
                                click: function() {
                                    var controller = this.controller,
                                        state = controller.state(),
                                        edit = controller.state('gallery-edit');

                                    edit.get('library').unshift( state.get('selection').models );
                                    state.trigger('reset');
                                    controller.setState('gallery-edit');
                                }
                            }
                        }
                    }) );
                };
            }
        })(jQuery);
    });
    </script>
    <?php
} );