Manipulating TGA Images

Truevision TGA, often referred to as TARGA, is a raster graphics file format created by Truevision Inc. (now part of Avid Technology). It was the native format of TARGA and VISTA boards, which were the first graphic cards for IBM-compatible PCs to support Highcolor/truecolor display. This family of graphic cards was intended for professional computer image synthesis and video editing with PCs; for this reason, usual resolutions of TGA image files match those of the NTSC and PAL video formats

Convert JPG to TGA

import aspose.pycore as aspycore
from aspose.imaging import Image
from aspose.imaging.imageoptions import TgaOptions
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
with Image.load(os.path.join(data_dir, "template.jpg")) as image:
image.save(os.path.join(data_dir, "result.tga"), TgaOptions())
if delete_output:
os.remove(os.path.join(data_dir, "result.tga"))

Convert Png to TGA

import aspose.pycore as aspycore
from aspose.imaging import Image, RasterImage
from aspose.imaging.fileformats.tga import TgaImage
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
with aspycore.as_of(Image.load(os.path.join(data_dir, "template.png")), RasterImage) as image:
with TgaImage(image) as tga_image:
tga_image.save(os.path.join(data_dir, "result.tga"))
if delete_output:
os.remove(os.path.join(data_dir, "result.tga"))

Save to TGA

import aspose.pycore as aspycore
from aspose.imaging import Image, Color
from aspose.imaging.fileformats.tga import TgaImage
import os
from datetime import timedelta, datetime
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
with aspycore.as_of(Image.load(os.path.join(data_dir, "template.tga")), TgaImage) as image:
image.date_time_stamp = datetime.now()
image.author_name = "John Smith"
image.author_comments = "Comment"
image.image_id = "ImageId"
image.job_name_or_id = "Important Job"
image.job_time = timedelta(days=10)
image.transparent_color = Color.from_argb(123)
image.software_id = "SoftwareId"
image.software_version = "abc1"
image.software_version_letter = 'a'
image.software_version_number = 2
image.x_origin = 1000
image.y_origin = 1000
image.save(os.path.join(data_dir, "result.tga"))
if delete_output:
os.remove(os.path.join(data_dir, "result.tga"))
view raw save-to-tga.py hosted with ❤ by GitHub