Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-com-gists/ad19aa95a82650f73945a2a58039dea5 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/ad19aa95a82650f73945a2a58039dea5 to your computer and use it in GitHub Desktop.

Aspose.Imaging for Python via .NET API allows to easy manipulate your jpeg2000 images or photos in your Python application or Web service.

You can:

  • Convert jpeg2000 image to raster formats;
  • Create jpeg2000 image;
  • Convert jpeg2000 image to vector formats;
  • Compress jpeg2000 images;
  • Operate with transparent jpeg2000 images;
  • Perform crop, rotate, resize and other typical operations to jpeg2000 images.

Interested ?

You may go further at : https://products.aspose.com/imaging/python-net/

from aspose.imaging import Image, LoadOptions
from aspose.imaging.fileformats.jpeg2000 import Jpeg2000Codec
from aspose.imaging.imageoptions import Jpeg2000Options
from aspose.imaging.sources import FileCreateSource
import os
if 'TEMPLATE_DIR' in os.environ:
templates_folder = os.environ['TEMPLATE_DIR']
else:
templates_folder = r"C:\Users\USER\Downloads\templates"
delete_output = 'SAVE_OUTPUT' not in os.environ
data_dir = templates_folder
# Setting a memory limit of 100 megabytes for target loaded image
# JP2 codec
load_options = LoadOptions()
load_options.buffer_size_hint = 100
with Image.load(os.path.join(data_dir, "template.jp2"), load_options) as image:
image.save(os.path.join(data_dir, "result.jp2"))
if delete_output:
os.remove(os.path.join(data_dir, "result.jp2"))
# Setting a memory limit of 10 megabytes for target created image
# JP2 codec
with Jpeg2000Options() as create_options:
create_options.codec = Jpeg2000Codec.JP2
create_options.buffer_size_hint = 10
create_options.source = FileCreateSource(os.path.join(data_dir, "result-2.jp2"), False)
with Image.create(create_options, 100, 100) as image:
image.save()
if delete_output:
os.remove(os.path.join(data_dir, "result-2.jp2"))
# J2K codec
with Jpeg2000Options() as create_options:
create_options.codec = Jpeg2000Codec.J2K
create_options.buffer_size_hint = 10
create_options.source = FileCreateSource(os.path.join(data_dir, "result.j2k"), False)
with Image.create(create_options, 100, 100) as image:
image.save()
if delete_output:
os.remove(os.path.join(data_dir, "result.j2k"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment