This functions is used to resize and center an image given a max size and a center location.
Essentially it uses an images height and width to determine it's aspect and then size it to fit a given max height and width parameters. It then will center the image based on an x & y coordinate passed in the function argument.
For this function to work correctly you will first need to determine the images width & Height (Variables: ImageWidth & ImageHeight) and then use the resulting variables from this function to set the images size and location (iheight, iwidth, CoordX, CoordY)
Thanks go to TJ Tigger for much of this...
This code would go in your global functions:
Here is some sample code illustrating how this can be used in a project:Code:--*************************** -- RESIZE_CENTER Image FUNCTION --*************************** function RESIZE_CENTER(maxwidth, maxheight, centerX, centerY) --If width larger than height resize based on width if (ImageWidth > ImageHeight) then iwidth = maxwidth --set width to max specifed in function call ratio = (ImageWidth / iwidth); -- determine ratio iheight = (ImageHeight / ratio); -- set height based on ratio --else height is larger and resize based on height else iheight = maxheight -- set height to max specified in function call ratio = (ImageHeight / iheight); --determine ratio iwidth = (ImageWidth / ratio); -- set width end -- Determine top left X & Y based on Image center coordinates sent in function call CoordX = centerX - (iwidth / 2); CoordY = centerY - (iheight / 2); end
Code:--Get Image Info ImageInfo = Image.GetFileInfo("AutoPlay\\Images\\indigorose.png"); --Get Files Image Dimensions ImageWidth = ImageInfo.Width ImageHeight = ImageInfo.Height --Call the function with max X,Y of 475 pixels and a Center of 456,245 RESIZE_CENTER(475, 475, 456, 245) --Hide Image to make the changes Image.SetVisible("Image", false); --Set Image Size based on function results Image.SetSize ("Image", iwidth, iheight); --Set Image position based on function results Image.SetPos("Image", CoordX, CoordY); --Load the image using the image path Image.Load ("Image", "AutoPlay\\Images\\indigorose.png"); --Set the image Visible again Image.SetVisible("Image", true);

