}
    }
}
#Make AJAX preview?:
if ($preview == true && isset($imagemagick_path)) {
    if (file_exists(get_temp_dir() . "/contactsheetrip.jpg")) {
        unlink(get_temp_dir() . "/contactsheetrip.jpg");
    }
    if (file_exists(get_temp_dir() . "/contactsheet.jpg")) {
        unlink(get_temp_dir() . "/contactsheet.jpg");
    }
    if (file_exists(get_temp_dir() . "/contactsheet.pdf")) {
        unlink(get_temp_dir() . "/contactsheet.pdf");
    }
    echo $pdf->GetPage();
    $pdf->Output(get_temp_dir() . "/contactsheet.pdf", "F");
    # Set up
    putenv("MAGICK_HOME=" . $imagemagick_path);
    putenv("PATH=" . $ghostscript_path . ":" . $imagemagick_path);
    # Path
    $ghostscript_fullpath = get_utility_path("ghostscript");
    $command = $ghostscript_fullpath . " -sDEVICE=jpeg -dFirstPage={$previewpage} -o -r100 -dLastPage={$previewpage} -sOutputFile=" . escapeshellarg(get_temp_dir() . "/contactsheetrip.jpg") . " " . escapeshellarg(get_temp_dir() . "/contactsheet.pdf") . ($config_windows ? "" : " 2>&1");
    run_command($command);
    $convert_fullpath = get_utility_path("im-convert");
    if ($convert_fullpath == false) {
        exit("Could not find ImageMagick 'convert' utility at location '{$imagemagick_path}'");
    }
    $command = $convert_fullpath . " -resize " . $contact_sheet_preview_size . " -quality 90 -colorspace " . $imagemagick_colorspace . " \"" . get_temp_dir() . "/contactsheetrip.jpg\" \"" . get_temp_dir() . "/contactsheet.jpg\"" . ($config_windows ? "" : " 2>&1");
    run_command($command);
    exit;
}