[Closed] Combining or overlaying images
Does Maxscript have the ability to overlay a transparent PNG on top of another image, like a watermark?
Yes, it does. The simplest way:
(
fn BlendImages mBackImg mFrontImg =
(
result = copy mBackImg
pasteBitmap mFrontImg result [0,0] [0,0] type:#blend
close mBackImg
close mFrontImg
return result
)
back = openBitMap "C:\img_01.png" -- bsckground image
front = openBitMap "C:\img_02.png" -- alpha image
display (BlendImages back front)
)
You can do much more advanced compositions by using type:#function and using your own code, but it might be too slow. In such cases you would need to switch to .Net, which has virtually no limits for this.
Thanks Jorge!
Works really nice
Instead of the display, to display, how would I be able to save the image to a certain folder?
A very simple way could be:
(
fn BlendImages mBackImg mFrontImg =
(
result = copy mBackImg
pasteBitmap mFrontImg result [0,0] [0,0] type:#blend
close mBackImg
close mFrontImg
return result
)
fn SaveImage mImg mFileName =
(
mImg.filename = mFileName
save mImg
close mImg
)
back = openBitMap "C:\img_01.png" -- bsckground image
front = openBitMap "C:\img_01.png" -- alpha image
img = BlendImages back front
SaveImage img "C:\img_03_result.png"
)
Note that it will use the default settings of the image format you chose. These settings can be also changed from MXS if you need to.
The result was splendid.
Also, as you said, the file was saved with default settings. That is something I have to dig into later.
Before I continue, I would like to ask if 3dsMax allows overwriting files, or if it only allows deleting files and then saving a new one?
As for the script, I would like to improve it more.
This is how I used it this far
(
fn BlendImages mBackImg mFrontImg =
(
result = copy mBackImg
pasteBitmap mFrontImg result [0,0] [0,0] type:#blendclose mBackImg
close mFrontImgreturn result
)fn SaveImage mImg mFileName =
(
mImg.filename = mFileName
save mImg
close mImg
)
back = openBitMap “$userscripts//splashes//_splash.png” – background image
front = openBitMap “$userscripts//splashes//_header.png” – alpha imageimg = BlendImages back front
SaveImage img “$userscripts//splashes//splash.bmp”
)
How would you do this; Instead of
front = openBitMap “$userscripts//splashes//_header.png”
… I would like to see something like
…_header” + MaxVersion + “.png”
… where MaxVersion gets its value from an if-else that works from version e.g. 2009 to 2016, so that if the running Max version is 2009, the file will be _header2009.png and so on, until 2016.
The Else gives us no suffix, in other words simply _header.png
Yes, you can overwrite a file with MXS.
I am not sure to understand what you need, but here is a function that returns a string (path) in the form you described (or as I understood it).
(
fn GetFrontImageFilename mHeader =
(
version = case ((maxversion())[1])/1000 of
(
11:"2009"
12:"2010"
13:"2011"
14:"2012"
15:"2013"
16:"2014"
17:"2015"
18:"2016"
default:""
)
-- If you will use a fixed folder, you could use this
userscripts = pathconfig.getdir #userscripts
folder = userscripts + "\\splashes\\"
return folder + mHeader + version + ".png"
)
GetFrontImageFilename "MyHeaderString"
)
You won’t believe me, but I was sure someone would post that code, and that person would most probably be you.
But it won’t work for <2009 versions. If I understood it correctly, they need to be empty strings. I know it can be handle with a simple if(
) but I like the way I wrote it, longer but clear.
would you believe or not I exactly knew about your reason (<2009) that’s why i set the smiley
Thanks Jorge for the last code regarding save. It works just great.
Also, I can reply my own question regarding overwriting – it works. I thought the file had to be erased first and then be overwritten.
As for the pre 2009-issue, would you please explain? It is not critical right now, but would be good to hear the explanation.
If I understood you correctly, the version check code won’t work on pre-2009, not even the [1]/1000 + 1998 way?
The version “check” I wrote as a case expression, will work just as you have described, it will give you a string with the Max version for 2009-2016 and previous versions to 2009 will return an empty string. And you can keep adding or removing items to the expression as needed.
My comment was regarding the “condensed” version Denis wrote, so for version 2008 it would return “2008” instead of “” and for previous versions it will simply return a wrong value (if the correct version would be needed), like 2007 for Max 9 and so on.
But in your case, if you prefer a condensed code, you can simply add a line after that like:
version = ((maxversion())[1]/1000 + 1998)
if version > 2009 then version = version as string else ""
-- OR
version = ((maxversion())[1]/1000 + 1998) as string
if version as integer < 2009 do version = ""
Here is the script by the way
–**************************************************
– Credits
– Haider of Sweden, www.haider.se (new design and functions)
– Jorge Rodríguez, (coding)
– Aaron Dabelow, email address removed from here (original script)– PURPOSE:
– Change the startup splash file for max– REQUIREMENT:
– Overlay image in transparent PNG-format. Naming convention:
– _header<version>.png, eg _header2016.png
– Splash images in BMP-format. Naming convention:
– 01.bmp, 02.bmp etc.
–***********************************************
– HISTORY:
– – v1.1 (2016-02-22): Add MAX version check and blends version-header
– on top of the splash before copying it to the destination.– – v1.0 (6.25.13): Initial script
–***********************************************
– TODO:
– – A better randomizing mechanism (eg prevent showing same image after eachother)–**************************************************
/* File User Rights Requirement
- Copy any image of choice to the 3dsMax folder and call it splash.bmp
- Set the Permissions (Properties > Security> Users: Full Controll)
*/(
fn GetFrontImageFilename mHeader =
(
version = case ((maxversion())[1])/1000 of
(
11:“2009”
12:“2010”
13:“2011”
14:“2012”
15:“2013”
16:“2014”
17:“2015”
18:“2016”
19:“2017”
default:””
)– If you will use a fixed folder, you could use this
userscripts = pathconfig.getdir #userscripts
folder = userscripts + “\splashes\”return folder + mHeader + version + “.png”
)fn BlendImages mBackImg mFrontImg =
(
result = copy mBackImg
pasteBitmap mFrontImg result [0,0] [0,0] type:#blendclose mBackImg
close mFrontImgreturn result
)fn BlendImages mBackImg mFrontImg =
(
result = copy mBackImg
pasteBitmap mFrontImg result [0,0] [0,0] type:#blendclose mBackImg
close mFrontImgreturn result
)fn SaveImage mImg mFileName =
(
mImg.filename = mFileName
save mImg
close mImg
)splashImages = getfiles “$userscripts//splashes//*.bmp”
back = openBitMap (splashImages[random 1 splashImages.count]) – random background splash image
– back = openBitMap “$userscripts//splashes//02.bmp” – single background image
front = openBitMap (GetFrontImageFilename “_header”) – alpha image
img = BlendImages back frontdisplay img – if you want to display the mixed image
SaveImage img “$Max//splash.bmp”)