Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 1a64ee3
  • /
  • scripts
  • /
  • convert_image.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:e98ff394e7c625e37c1b5b94e35bda282c3b42c2
directory badge Iframe embedding
swh:1:dir:272f8332864259a7ea7222daae72cb0bbbeb5ee6

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
convert_image.py
#!/usr/bin/env python3

# Copyright (c) 2020-2022, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.

import argparse
import common
import numpy as np
import os
import PIL

def parse_args():
	parser = argparse.ArgumentParser(description="Convert image into a different format. By default, converts to our binary fp16 '.bin' format, which helps quickly load large images.")
	parser.add_argument("--input", default="", help="Path to the image to convert.")
	parser.add_argument("--output", default="", help="Path to the output. Defaults to <input>.bin")
	args = parser.parse_args()
	return args

if __name__ == "__main__":
	args = parse_args()
	PIL.Image.MAX_IMAGE_PIXELS = 10000000000
	print(f"Loading {args.input}")
	img = common.read_image(args.input)
	print(f"{img.shape[1]}x{img.shape[0]} pixels, {img.shape[2]} channels")

	if not args.output:
		output = os.path.splitext(args.input)[0] + ".bin"
	else:
		output = args.output

	print(f"Writing {output}")
	common.write_image(output, img.astype(np.float16))

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API