Node Jimp | Blit

Introduction
The blit() function is an inbuilt function in Nodejs. It is used to combine two bitmap patterns. | Jimp which combines several bitmaps into one using a boolean function.

Parameters:

  • src – This parameter stores the source of the image to blit.
  • x – This parameter takes x position to blit the image.
  • y – This parameter takes y position to blit the image.
  • srcx (optional) – This parameter takes the x position from which to crop the source image.
  • srcy (optional) – This parameter takes the y position from which to crop the source image.
  • srcw (optional) – This parameter takes the width to which to crop the source image.
  • srch (optional) – This parameter takes the height to which to crop the source image.
  • Input Images:



    Example 1:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // npm install --save jimp
    // import jimp library to the environment
    var Jimp = require('jimp');
      
    // User-Defined Function to read the images
    async function main() {
      const image1 = await Jimp.read('../gfg.png');
      const image2 = await Jimp.read('../gfg1.png');
      
      // call to blit function 
      image1.blit(image2, 20, 40)
      
      // write image
      .write('blit1.png');
      console.log('Image Processing Completed');
    }
    main();

    chevron_right

    
    

    Output:

    Example 2:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // npm install --save jimp
    // import jimp library to the environment
    var Jimp = require('jimp');
      
    // User-Defined Function to read the images
    async function main() {
      const image1 = await Jimp.read('../gfg.png');
      const image2 = await Jimp.read('../gfg1.png');
      
      // call to blit function along with optional parameters
      image1.blit(image2, 20, 40, 130, 30, 440, 80);
      
      // write image
      .write('blit2.png');
      console.log('Image Processing Completed');
    }
    main();

    chevron_right

    
    

    Output:

    Reference: https://www.npmjs.com/package/jimp



    My Personal Notes arrow_drop_up

    Check out this Author's contributed articles.

    If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

    Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.