This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LDDestroier's profile picture

NFT Extra: the essential API for your NFT needs!

Started by LDDestroier, 24 May 2018 - 02:49 PM
LDDestroier #1
Posted 24 May 2018 - 04:49 PM
I had made an "extra" version of NFP earlier, so I thought I'd try to rewrite it for NFT as well.
So, I give you…
NFT Extra


Not only does this API allow basic things such as loading and drawing images, but it also allows for various transformations as well!
  • Stretching images to arbitrary sizes!
  • Saving multiple NFT images as one layered image (Animated NFT)
  • Merging two or more images at differing positions!
  • Flipping images!
  • Converting from NFP!
  • Darkening and lightening images!
  • Converting to grayscale!
  • Cropping!
  • Rotating!
It's the best way to use the NFT image format, probably! Feel free to put it in your programs.

API: (either use os.loadAPI or dofile/require)

wget https://github.com/LDDestroier/NFT-Extra/raw/master/nfte.lua nfte

Demo:

wget https://raw.githubusercontent.com/LDDestroier/NFT-Extra/master/demo.lua demo

Examples of use:
Spoiler

image = nfte.loadImage(string filepath)

image = nfte.loadImageData(string contentsOfImageNFT)

contentsOfImageNFT = nfte.unloadImage(table image)

image = nfte.convertFromNFP(table loadedImageNFP)

nfte.drawImage(table image, number x, number y)

nfte.drawImageTransparent(table image, number x, number y)

nfte.drawImageCenter(table image, number x, number y)

nfte drawImageCenterTransparent(table image, number x, number y)

imageXsize, imageYsize = nfte.getSize(table image)

lightImage = nfte.lighten(table image, number repeatTimes)

darkImage = nfte.darken(table image, number repeatTimes)

stretchedImage = nfte.stretchImage(table image, number sizeX, number sizeY, boolean doRepeatCharacters)

pixelatedImage = nfte.pixelateImage(table image, number intensity)

mergedImage = nfte.merge({table image1, number x, number y}, {table image2, number x, number y}, ...)

croppedImage = nfte.cropImage(table image, number x1, number y1, number x2, number y2)

reversedImage = nfte.flipX(table image)

upsideDownImage = nfte.flipY(table image)

animatedImage = {
	image1,
	image2,
	image3
}
ANFTfileContents = nfte.unloadImage(animatedImage)
ANFTimageData = nfte.loadImageData(ANFTfileContents)

Demo video:
[media]http://www.youtube.com/watch?v=MBrqlhVwRu8[/media]
Edited on 22 December 2018 - 07:39 AM
LDDestroier #2
Posted 20 December 2018 - 07:05 AM
The rotation function has been fixed up, so there aren't any black dots in the middle of an image.
nfte.flipX now flips most teletext characters so images that use them won't look weird.
If you use nfte.unloadImage on a table containing other NFT table images, it will turn it into a multilayered NFT image, which can be read normally with nfte.loadImage or nfte.loadImageData. Expect this as the new PAIN file format.

There's also a new demo available to show NFTE's functions, so try that out if you want to see just what is possible.

nfte.stretchImageKeepAspect() has also been added. It's the same as stretchImage, but maintains the image's aspect ratio for you.

nfte.merge() can also accept 'true' as a coordinate in its arguments, which will center the image in the corresponding coordinate.
Edited on 28 February 2019 - 05:25 PM