GifOptions Class

Summary: The API for Graphical Interchange Format (GIF) raster image file creation offers
developers comprehensive options for generating GIF images with precise
control. With features to set background color, color palette, resolution,
interlaced type, transparent color, XMP metadata container, and image
compression, this API ensures flexibility and efficiency in creating optimized
and visually appealing GIFs tailored to specific application requirements.

Module: aspose.imaging.imageoptions

Full Name: aspose.imaging.imageoptions.GifOptions

Inheritance: ImageOptionsBase

Aspose.Imaging Version: 24.5.0

Constructors

NameDescription
GifOptions()Initializes a new instance of the GifOptions class.
GifOptions(gif_options)Initializes a new instance of the GifOptions class.

Properties

NameTypeAccessDescription
background_colorColorr/wGets or sets the background color.
background_color_indexbyter/wGets or sets the GIF background color index.
buffer_size_hintintr/wGets or sets the buffer size hint which is defined max allowed size for all internal buffers.
color_resolutionbyter/wGets or sets the GIF color resolution.
disposedboolrGets a value indicating whether this instance is disposed.
do_palette_correctionboolr/wGets or sets a value indicating whether palette correction is applied.
full_frameboolr/wGets or sets a value indicating whether [full frame].
has_trailerboolr/wGets or sets a value indicating whether GIF has trailer.
has_transparent_colorboolr/wGets or sets a value indicating whether GIF image has transparent color.
interlacedboolr/wTrue if image should be interlaced.
is_palette_sortedboolr/wGets or sets a value indicating whether palette entries are sorted.
loops_countintr/wGets or sets the loops count (Default 1 loop)
max_diffintr/wGets or sets the maximum allowed pixel difference. If greater than zero, lossy compression will be used.
Recommended value for optimal lossy compression is 80. 30 is very light compression, 200 is heavy.
It works best when only little loss is introduced, and due to limitation of the compression algorithm very high loss levels won’t give as much gain.
The range of allowed values is [0, 1000].
multi_page_optionsMultiPageOptionsr/wThe multipage options
paletteIColorPaletter/wGets or sets the color palette.
pixel_aspect_ratiobyter/wGets or sets the GIF pixel aspect ratio.
resolution_settingsResolutionSettingr/wGets or sets the resolution settings.
sourceSourcer/wGets or sets the source to create image in.
vector_rasterization_optionsVectorRasterizationOptionsr/wGets or sets the vector rasterization options.
xmp_dataXmpPacketWrapperr/wGets or sets the XMP metadata container.

Methods

NameDescription
clone()Clones this instance.

Constructor: GifOptions()

 GifOptions() 

Initializes a new instance of the GifOptions class.

Constructor: GifOptions(gif_options)

 GifOptions(gif_options) 

Initializes a new instance of the GifOptions class.

Parameters:

ParameterTypeDescription
gif_optionsGifOptionsThe GIF Options.

Method: clone()

 clone() 

Clones this instance.

Returns

TypeDescription
ImageOptionsBaseReturns shallow copy of this instance

Examples

This example shows how to load a pixels information in an array of Color, manipulates the array and set it back to the image. To perform these operations, this example creates a new Image file (in GIF format) using MemoryStream object.


from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage, Color
from aspose.imaging.externsions import StreamExtensions as strm_ext
from aspose.imaging.imageoptions import GifOptions
from aspose.imaging.sources import StreamSource

# Create an instance of MemoryStream
with strm_ext.create_memory_stream() as stream:
	#Create an instance of GifOptions and set its various properties including the Source property
	with GifOptions() as gifOptions:
		gifOptions.source = StreamSource(stream)

		# Create an instance of Image
		with as_of(Image.create(gifOptions, 500, 500), RasterImage) as image:
			# Get the pixels of image by specifying the area as image boundary
			pixels = image.load_pixels(image.bounds)

			yellow_color = Color.yellow
			blue_color = Color.blue
			#Loop over the Array and sets color of alternative indexed pixel
			for index in range(pixel.length):
				if index % 2 == 0:
					#Set the indexed pixel color to yellow
					pixels[index] = yellow_color
				else:
					#Set the indexed pixel color to blue
					pixels[index] = blue_color

			#Apply the pixel changes to the image
			image.save_pixels(image.bounds, pixels)

			# save all changes.
			image.save()

	# Write MemoryStream to File
	stream.seek(0)
	with open(r"C:\temp\output.gif", "wb") as fileStream:
		fileStream.write(stream.read())
}

This example demonstrates the use of different classes from imageoptions package for export purposes. A gif image is loaded as an instance of Image and then exported out to several formats.


from aspose.imaging import Image
from aspose.imaging.imageoptions import BmpOptions, JpegOptions, PngOptions, TiffOptions
from aspose.imaging.fileformats.tiff.enums import TiffExpectedFormat
from os.path import join as path_join

directory = "c:\\temp\\"
#Load an existing gif image as an instance of Image class
with Image.load(path_join(directory, "sample.gif")) as image:
	# Export to BMP file format using the default options
	image.save(path_join(directory, "output.bmp"), BmpOptions())
	# Export to JPEG file format using the default options
	image.save(path_join(directory, "output.jpg"), JpegOptions())
	# Export to PNG file format using the default options
	image.save(path_join(directory, "output.png"), PngOptions())
	# Export to TIFF file format using the default options
	image.save(path_join(directory, "output.tif"), TiffOptions(TiffExpectedFormat.DEFAULT))