Code Monkey home page Code Monkey logo

Comments (2)

brianium avatar brianium commented on August 15, 2024

Since watermark.js accepts multiple types of resources, you could just keep a single Image instance around for the watermark, and use File objects (from a user upload) for the images to watermark.

var mark = new Image();
mark.onload = function () {
  //loop through file inputs
  var input = document.querySelector('input[type=file]');
  for (var i = 0; i < input.files.length; i++) {
    // use the same loaded image in each iteration
    watermark([input.files[i], this])
      .blob(watermark.image.lowerRight(0.5))
      .then(handleUpload);
  }
}
mark.src = '/path/to/watermark.png';

function handleUpload(blob) {
  // whatever your upload implementation is
}

This is just what comes to mind - there may be other ways to do it, but the idea is you can cache the watermark image and use the same instance in multiple watermark operations.

Does this help?

from watermarkjs.

brettmcdade avatar brettmcdade commented on August 15, 2024

Thanks for the prompt response. You helped me get the wheels turning.

My needs were very basic. I'm not a JavaScript wizard by any means so after poking around all day at the upload.js code and I was able to get it to do what I needed by stripping out code and changing the setTarget function to load the watermark url

function setTarget(file) {
  watermark([file, 'images/logo.jpg']) 
      .image(watermark.image.lowerRight())
      .then(function (img) {
        document.getElementById('preview').appendChild(img);
      })
}

from watermarkjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.