You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: nup.go
    path of file: ./repos/pdfcpu/pkg/api
    
    the code of the file until where you have to start completion: /*
	Copyright 2020 The model Authors.

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

		http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS O
    
func NUp(rs io.ReadSeeker, w io.Writer, imgFiles, selectedPages []string, nup *model.NUp, conf *model.Configuration) error {
	if conf == nil {
		conf = model.NewDefaultConfiguration()
	}
	conf.Cmd = model.NUP

	if log.InfoEnabled() {
		log.Info.Printf("%s", nup)
	}

	var (
		ctx *model.Context
		err error
	)

	if nup.ImgInputFile {

		if ctx, err = NUpFromImage(conf, imgFiles, nup); err != nil {
			return err
		}

	} else {

		if ctx, err = ReadAndValidate(rs, conf); err != nil {
			return err
		}

		pages, err := PagesForPageSelection(ctx.PageCount, selectedPages, true, true)
		if err != nil {
			return err
		}

		// New pages get added to ctx while old pages get deleted.
		// This way we avoid migrating objects between contexts.
		if err = pdfcpu.NUpFromPDF(ctx, pages, nup); err != nil {
			return err
		}

	}

	return Write(ctx, w, conf)
}