Guide

How to Render Images Using JES

JES allows you to load images and check them for future editing.


JES is software that allows you to programmatically edit photos, videos, and sounds. It uses the Jython programming language, which closely follows the syntax of Python.


Besides using JES to edit an image, you can use built-in functions to prompt the user to select an image and render the image in a new window. Other built-in functions can copy an image or get other information like height and width.

You can also open another window where you can examine each pixel in the file to get information about the colors of the image.


How to render an existing image with JES

Jython closely follows Python syntax, which means that indentation determines the structure of your code. If necessary, you can review what Python is and what you can use it for, or other useful Python commands for beginners.

You can render files by prompting the user to select a file through a file dialog box. Once the user has selected an image, you can render the selected image in another window.

  1. Open the JES software on your computer.
  2. In the programming window at the top of the JES interface, create a new function called displayPic():
     def displayPic(): 
  3. Inside the displayPic() function, use the pickAFile() built-in function. This will open a file explorer and let you choose which image you want to render. Save the selected image in a new variable called “File”:
     file = pickAFile() 
  4. Use the makePicture() function to create a new picture object with the selected file:
     pic = makePicture(file) 
  5. Use the show() function to render the image. This will open the selected image in a new window:
     show(pic) 
  6. To run the function, click load program Button between the command line and the programming area. Click on Yes when prompted to save. Once loaded, call the displayPic() function from the command line:
     displayPic() 
    Loaded program with displayPic function in terminal
  7. When the function runs, a file explorer will appear. Use it to select the image you want to render and click on it Open.
    JES image selection window
  8. Confirm that your selected image will be rendered in a new window.
    Beach image rendered in the window

To view information about the image

You can also get information about the image, e.g. B. the location of the local file path, the width or height. JES provides built-in functions such as getWidth() and getHeight() that you can use to retrieve this information.

  1. In the programming window, create a new function called printHeightAndWidth():
     def printHeightAndWidth(): 
  2. In the new printHeightAndWidth() function, use the pickAFile() function to prompt the user to select an image. Use the selected image to create a new image object:
     file = pickAFile()
    pic = makePicture(file)
  3. Get the width of the image using the getWidth() function and display the result:
     width = getWidth(pic)
    print "Width of the photo: " + str(width)
  4. Get the height of the function using the getHeight() function and display the result:
     height = getHeight(pic)
    print "Height of the photo: " + str(height)
  5. Print the location of the selected file:
     print "File Location: " + file 
  6. Click on that load program press and select Yes when prompted to save. Type the printHeightAndWidth() function on the command line to run it:
     printHeightAndWidth() 
    Program with heightWidth function loaded in terminal
  7. Use the File Explorer window to select an image and click Open.
    JES image selection window
  8. Display the image’s width, height, and file path information on the command line.
    Image information is displayed on the command line

    How to duplicate an image

    You can duplicate an image using the plicatePicture() function. This clones an existing image into a second image object. This allows you to make changes to a copy of an image without affecting the original image.

    1. In the programming window, create a new function called DuplicateImage():
       def duplicateImage(): 
    2. Inside the new DuplicateImage() function, use the pickAFile() function to prompt the user to select an image. Use the selected image to create a new image object:
       file = pickAFile()
      originalPic = makePicture(file)
    3. To clone the picture, use the DuplicatePicture() function. Enter the original image as an argument to the function. The DuplicatePicture() function returns a cloned version of the original image. Store the cloned image in a new variable called “pic2”:
       pic2 = duplicatePicture(originalPic) 
    4. Use the show() function to display both images:
       show(originalPic)
      show(pic2)
    5. Click on that load program press and select Yes when prompted to save. Type the DuplicateImage() function on the command line to run it:
       duplicateImage() 
      Program with DuplicatePic function loaded in terminal
    6. Use the File Explorer window to select an image and click Open.
    7. Both the original image and the cloned image will open in two separate windows.
      Two images rendered in JES

    How to explore pixels in an image

    The ability to view or select every pixel in an image is an extremely useful feature that many online photo editors use for Photoshop effects. In JES you can use the built-in explore() function to open the image in explore mode.

    Explore mode opens the image in a new window and provides additional functionality that the show() function does not provide. For example, you can select any pixel in the photo to show information about it, such as: B. its color or x and y coordinates.

    1. In the programming window, create a new function called exploreImage():
       def exploreImage(): 
    2. In the new exploreImage() function, use the pickAFile() function to prompt the user to select an image. Use the selected image to create a new image object:
       file = pickAFile()
      pic = makePicture(file)
    3. Use the explore() function to open the image in explore mode.
       explore(pic) 
    4. Alternatively, you can use the built-in openPictureTool() function. You can also use this function to examine pixels within a selected image:
       openPictureTool(pic) 
    5. Click on that load program press and select Yes when prompted to save. Type the exploreImage() function on the command line to run it:
      Program loaded with explorePic function in terminal
    6. Select an image with File Explorer to view the image in explore mode. Here you can select any pixel in the image to view its x and y coordinates. You can also see the pixel’s RGB color values.
      Image rendered in explore mode in JES

    Rendering images with JES

    Now that you understand how images are rendered using JES, let’s examine pixels more closely. You can use this approach to make certain edits to your photos.

    Because Jython is very similar to Python, you can try more Python exercises to solidify your Python knowledge.

Read  How to Paint Upholstery

Related Articles

Leave a Reply

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

Check Also
Close
Back to top button