www.tombraiderforums.com  

Go Back   www.tombraiderforums.com > Tomb Raider Modding > Tomb Raider Level Editor > Tutorials and Resources

Closed Thread
 
Thread Tools
Old 27-02-21, 09:33   #1
Richard_trle
Explorer
 
Richard_trle's Avatar
 
Join Date: Aug 2003
Location: Brazil
Posts: 734
Default Using ImageMagick to create a Texture Atlas from multiple images

Hi everyone! I did something fun today, and I would like to share with you all.

For those who are wondering, ImageMagick is a free and open-source image manipulation software. With it you can create, display, convert, modify and edit rasterized images. ImageMagick is capable of converting over 200 formats, including the most commonly available and used, such as PNG, JPEG, BMP and TGA. Then I'm pretty sure you are going to ask,

why use ImageMagick?

Well, for the sake of practicality of course, with ImageMagick we can convert dozens of single images into a readily available texture atlas which can be used by NGLE, Tomb Editor and even with the Classic Editor!

Before we jump into it, make sure to install ImageMagick

https://imagemagick.org/script/download.php#windows

The suggested package is "ImageMagick-7.0.11-1-Q16-HDRI-x64-dll.exe", but if you have a 32bit Windows, you can download the Q16-HDRI-x86-dll.exe package. At the time of installation there is an option that asks you to install legacy utilities, make sure to check it, because checking that box makes ImageMagick available to use through command line. You can check if it is installed on the command line with the following command:

Code:
magick identify --version
If it is not available on your path, try to add manually to the System Path. There is a tutorial in this page, showing how to set Environment Variables in Windows 10 [LINK]. Once you have ImageMagick installed, create or browse to a desired folder with all images you want to create your Texture set. We need to open that folder in the command line, you can achieve that through cmd.exe, or with Windows PowerShell or through Windows Explorer. If you know how to navigate through folders using command line, you are free to skip the next part.

In Windows 10 you have an option to open a folder in Windows PowerShell by right clicking that folder while holding the shift button (Shift+RClick), as shown in the image below.



Once you are in the folder, we need to perform three actions, [1] we need to convert multiple image types in a single one, [2] then we need to resize them (in this tutorial I am going to resize images to 128x128), but you are free to choose the aspect ratio you want, be it 32, 64 or 256. [3] And, lastly we are going to combine all these images into a single Texture Atlas.

Images with different proportions can also be used, but they need to be ordered to prevent tile mismatching, for example lets say you have an image with 128x64 resolution. Then you need to make sure that the next image has an 1:1 aspect ratio, in this case a 128x128 image.

1 - Convert images

Before we start, make sure to have a backup in case something goes wrong. Even though this step creates new images, as Mogrify documentation states, it is a dangerous tool and can easily destroy the original image. Since we are creating a texture atlas, we need to convert every image to a single format (TGA in this case), or else we would need advanced parsing skills to combine them. If all your pictures share the same file format you are free to proceed to the next step. For each file format in your folder of pictures type the following command in the console:

Code:
mogrify    -format tga *.png
Where you substitute the *.png above with every other existing file format you have within the folder. You can also change the destination format, by simply changing tga to either bmp, png or any other format supported by the editor of your choice.

Once you performed the conversion and if you have a backup, you can even erase all the other files with different formats. You can also leave them be, since it doesn't make any difference for the next steps.

2 - Resize images

We need to resize the images, because we need to guarantee that our texture atlas is going to have a necessary aspect ratio between each tile to be usable within the editor. It does not matter if there are pictures with actual different aspect ratio, but as I mentioned above, you need to order those pictures, so when we combine them in the next step, there are no tiles mismatching, or else you are going to have a seesaw of textures.

This step is DANGEROUS, so make sure you have a backup, because the conversion is made in place, which overwrites all the original files. You can resize all the images with the following command:

Code:
magick mogrify -resize 128x128 *.tga
The resizing is attempted tentatively, ImageMagick guarantees that at least one side of the resulting images WILL have either the desired height or width. This is also awesome, because we don't need to prick about images with different aspect ratio. In case you have pictures with different aspect ratio, just order them manually by renaming them so they are always paired with a 1:1 image. Once you are done, check the results with an Image Viewer of your choice, just to make sure the images are ordered. In this example I am using XnView, which is an amazing image viewer.



Once you are finished, proceed to the last step.

3 - Combine all images together

To combine together all the desired images, you use the following command:

Code:
montage -mode concatenate -tile 1x *.tga out.tga
In this step you can also make several modifications, including the order which files are appended, the number of columns, the background color and if there is any prefix. So for example, lets say I want a "2 column" Texture Atlas, with a black background and with only files prefixed with "Tomb-". I would write the following command:

Code:
montage -mode concatenate -background black -tile 2x Tomb-*.tga out.tga
If you want finer details on how to customize this command, I refer to ImageMagick Documentation [link]. This step is the reason why I made this tutorial, with it I made the whole process of generating a texture atlas a lot easier. With it you can create Atlas consisting of dozens of images with a simple set of commands, and the results speak for themselves:



I hope you all enjoy this tutorial, if you have any questions do not hesitate to contact me and thanks for reading.

Last edited by Richard_trle; 27-02-21 at 09:35.
Richard_trle is offline  
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 14:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.