Technology0How to Add Text to Images in a JES Application

[ad_1]

Annotate your images or add other types of text label with JES.


JES is a development environment that allows you to process and edit a variety of media. For images, this includes uploading photos or adding different filter effects.


If you are editing images, you may want to add text at a particular set of coordinates. If so, you can use built-in JES functions such as addText() or addTextWithStyle(). These functions allow you to configure where the text appears, the color of the text, and other styling options.


How to Add Text Onto an Image

You can add text onto an image in JES by using the addText() function. Since JES uses the Jython programming language, make sure you brush up on your Python syntax with some basic Python examples.

  1. Open the JES application on your computer.
  2. In the programming window, create a new function called textOnImage:
     def textOnImage(): 
  3. Inside the function, use the pickAFile() function to ask the user to select a local file on their computer:
     file = pickAFile()  
  4. Create a picture object using the makePicture() function:
     pic = makePicture(file) 
  5. Declare the string that you would like to add to the image:
     str = "This is a test." 
  6. Use the addText() function to add the text onto the image. For the first argument, enter the image. For the second and third arguments, enter the coordinates where you want the text to show. Pass the string variable as the final argument:
     addText(pic, 50, 50, str) 
  7. By default, the color of the text is black. You can change the color of the text by passing the name of a color as the fifth argument:
     addText(pic, 100, 100, str, blue) 
  8. Show the picture using the show() function to render the image in JES onto the screen:
     show(pic) 
  9. Click on the Load Program button, located underneath the programming area. If prompted to save the file, click on Yes.
    Load program button in JES

  10. Enter the textOnImage() function into the command line to run it:
    Run text function in command line

  11. Wait for the function to display the image with text.
    Show image with text

How to Add Styled Text

You can also add styled text onto an image in JES using the addTextWithStyle() function.

  1. Create a new function called StyledTextOnImage:
     def StyledTextOnImage(): 
  2. Inside the function, import “java.awt.Font”. This will give you access to certain styles such as bold font.
     import java.awt.Font as Font 
  3. Use the pickAFile() function to ask the user to select a local file on their computer:
     file = pickAFile()  
  4. Use the makePicture() function to create a picture object:
     pic = makePicture(file) 
  5. Declare the string that you would like to add to the image:
     str = "This is a test." 
  6. Use the makeStyle() function to create a font style object. The makeStyle() function allows you to change the font family and size. You can also use it to make text bold, italicized, or underlined.
     myFont = makeStyle("Arial", Font.BOLD, 64) 
  7. Use the addTextWithStyle() function to add the text onto the image. As before, the arguments include the image itself, the x and y coordinates of the text location, and the text string. Additionally, input the custom style as the fifth argument:
     addTextWithStyle(pic, 50, 50, str, myFont) 
  8. As with addText(), the text is black by default, but you can specify a different color with an extra, sixth parameter:
     addTextWithStyle(pic, 100, 100, str, myFont, blue) 
  9. Show the image:
     show(pic) 
  10. Click on the Load Program button, located underneath the programming area. If prompted to save the file, click on Yes.
    Load program button in JES

  11. Enter the StyledTextOnImage() function into the command line to run it:
     StyledTextOnImage() 
    Run styled text function in command line

  12. Wait for the function to display the image with text.
    Show image with styled text

Adding Text to Images Using JES

Now you’ve seen how to add text to images, you can check out some of the other interesting things you can do to images with JES. This powerful environment lets you crop and scale images, apply filters, and carry out color transformations.

[ad_2]

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *