Add Text to a Picture@lwx228 asked How do add text to a cell that has an image loaded? This idea is pretty simple: put the picture in a frame box, use a graphic script to decorate, take a new picture. The details to get a nice round-trip image are a bit more complicated. The frame needs to be sized and scaled, and the picture positioned, and the final image cropped.
// open the original
original = New Image(
"https://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Oroblanco_%28sweetie%29_fruits.jpg/320px-Oroblanco_%28sweetie%29_fruits.jpg"
);
{xSize, ySize} = original << size;
// use a frame to do the drawing, make the original fit the frame exactly
gb = Graph Box(
<<BACKGROUNDCOLOR></BACKGROUNDCOLOR>
The results, below, shows the image filling the frame box with the decorations, and three images below. The left image is the original, the center is modified, and the right is the difference. The difference is mostly black, no change, which is good. The text in the difference is fuzzy because the anti-aliasing made subtle changes at the edge of the text.
Circles and text added on top of fruit picture.Circles and text added on top of fruit picture.
Picture from Crop a JPG Image explaining how crop works.
View more...
The zero-based pixel indexes are on the hairlines between the pixels.The zero-based pixel indexes are on the hairlines between the pixels.
Use a graphics frame box to add text and lines on top of a picture.Use a graphics frame box to add text and lines on top of a picture.
Use a frame box to add text and lines to a picture.
Re: Add Text to a PictureOK
Thank Craige!
gb[framebox(1)]<<ADD image=""></ADD>
Re: Add Text to a PictureYes. It is a little harder, explanations below.
// open the original
original = New Image(
"https://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Oroblanco_%28sweetie%29_fruits.jpg/320px-Oroblanco_%28sweetie%29_fruits.jpg"
);
{xSize, ySize} = original << size;
overlay1 = new image("https://us.v-cdn.net/6038925/uploads/images/35680iA0171FFF13D53E06/NaturalCat.png");// cat
{xOverlay1Size, yOverlay1Size} = overlay1 << size;
dt = open("$sample_data/big class families.jmp","invisible");
overlay2 = dt:picture[1];// katie
overlay2<<SCALE></SCALE>
Pictures added over another picture.Pictures added over another picture.
The graphic script can't add the picture. Use the <
The GraphBox(...) function takes three kinds of arguments: parameters, messages, and scripts. Best practice is to put the parameters and messages first, and a single script at the end. The parameters and messages are separated by commas. The script uses semicolons to separate statements.
gb = Graph Box(
<<BACKGROUNDCOLOR></BACKGROUNDCOLOR>
Many, many graph box scripts have been written with accidental commas rather than semicolons. Each comma causes a new script to begin, separated from the previous script. It is a bit of extra overhead for JMP to run multiple scripts when one would do.
Re: Add Text to a PictureHello Craige!
I wonder if JSL can superimpose a small image at the specified position of the image?
I searched the help manual and couldn't find the answer.
That's all I can think of.Thanks Experts!
img = Open( "$SAMPLE_IMAGES/tile.jpg", jpg );
{x, y} = img << size;
img << crop( Left( 100 ), Right( x - 251 ), top( 0 ), bottom( y - 0 ) );
{x1, y1} = img << size;
img2 = Open( "$SAMPLE_IMAGES/black rhino footprint.jpg", jpg );
img << copy;//??
img2 << paste(100,25);//??
obj = New Window( "paste", New Image( img2 ) );<BR />