Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 4913 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I have some maps and symbols as .png files (stored in container fields) that I need to combine in a FileMaker solution. I've tried looking in to doing it using ImageMagick and the command line, but it suddenly struck me that this may be something that could be done using ScriptMaster. I've seen some code that lets you combing images and text, but not images and images ...

Essentially, I need to overlay symbols at certain coordinates. I can do the coordinate calcs no problem, so the issue is more a case of, given two transparent pngs how do I combine them without losing transparency? (Both the map and the symbol may need to be transparent due to the need to overlay them later on, externally to FileMaker).

Ideally something like combinePngImage(background_container, foreground_container, foreground_x, foreground_y) so that I could set the contents of a container field to be the combination of the two, given the top left, top right coordinates of the foreground image.

Any pointers gratefully received!

Kind regards,

R

Posted

I've managed to cobble something together myself from various cookbook sources and the ScriptMaster reference file:


combineImage ( backgroundImg ; foregroundImg ; x ; y )



import javax.imageio.ImageIO;

import java.awt.*;

import java.awt.image.BufferedImage;

import java.io.File;

import java.net.URL;



// get container data

InputStream bgImgContainer



try{

  bgImgContainer = fmpro.getContainerStream(backgroundImg)

}catch(e){

  throw new Exception('Could not get data from background image container (make sure container field name is passed as text)')

}



// test if container field is empty

if( bgImgContainer == null ) {

  throw new Exception('Background image container field is empty')

}



bgImgName = fmpro.getContainerFileName(backgroundImg);



InputStream fgImgContainer



try{                                         

  fgImgContainer = fmpro.getContainerStream(foregroundImg)

}catch(e){

  throw new Exception('Could not get data from foreground image container (make sure container field name is passed as text)')

}



// test if container field is empty

if( fgImgContainer == null ) {

  throw new Exception('Foreground image container field is empty')

}



fgImgName = fmpro.getContainerFileName(foregroundImg);



int xCoord = Integer.parseInt(x);

int yCoord = Integer.parseInt(y);



// load image from container data

BufferedImage result = ImageIO.read(bgImgContainer);

BufferedImage overlay = ImageIO.read(fgImgContainer);



int fgWidth  = overlay.getWidth(null);

int fgHeight = overlay.getHeight(null);



Graphics2D graphics = result.createGraphics();



// overlay the foreground at given coordinates and actual size

graphics.drawImage(overlay, xCoord, yCoord, fgWidth, fgHeight, null);



graphics.dispose();



File output = File.createTempFile(bgImgName, ".png");

ImageIO.write(result, "png", output);

return output;

Not sure about the coding style, but it does what I need, and may be of help to someone else

This topic is 4913 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.