Review of JavaScript function & steganography

The previous post: review of JavaScript syntax basics


A function consists of three elements:

  • function name
  • parameter
  • return

Example 1. frame an image with black border:


Example 2. more red:


Example 3. crop two images of different sizes:


Example 4. enlarge the image:

note: the top left pixel is at position (0,0)



  • Rationale

The idea is that you have image A and image B, and you want to hide image B inside A. Suppose A is 10111100, B is 11011001. You would take 1011 from A and 1101 from B (use 16=2^4 to get those numbers). Then, we can combine them into 10111101 and get the new image with a hidden image in it!

pa: pixel for image A

npa: the new pixel for image A

pb: pixel for image B

npb: the new pixel for image B

npa. setRed(Math.floor(pa/16) * 16)
npb. setRed(Math.floor(pb.getRed()/16))
  • complete coding example:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s