Giter Club home page Giter Club logo

watermark's Introduction

jQuery plugin Watermark

npm FOSSA Status

JQuery plugin Watermark help you seal batch of images, like a stamp tool.

Because this plugin is written in HTML5 and Javascript, so it will operate without a server for image processing, bandwidth limit is no longer the thing you need to worry.

Suitable uses for low-bandwidth web server, or web creation services, free forums without management server as Blogspot, Forumotion, ...

Demo

https://lelinhtinh.github.io/watermark/

Features

  1. Using an image or text to stamp.
  2. Allows you to select a position to stamp on 8 corners of the image.
  3. Size and format options after the stamped image.
  4. Export image to base64 type, so might instead directly into the old photos or upload server allows, for example, Imgur.

Defect

  1. Does not work on older browsers that don't support HTML5.
  2. Cannot use images be limited server CORS headers according to the domain name. If this server in your rights management, you need to set up Apache as follows:
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "referer, range, accept-encoding, x-requested-with"

Download

Direct download file watermark.zip or watermark.tar.gz or use the command line:

Git

git clone https://github.com/lelinhtinh/watermark.git

Bower

bower install watermark

npm

npm install watermark

How to use

This plugin requires jQuery library from 1.5 or above, add it at the end of your HTML document as follows:

<!-- jQuery 1.5+ -->
<script src="jquery.js" type="text/javascript"></script>
<!-- jQuery plugin Watermark -->
<script src="jquery.watermark.js" type="text/javascript"></script>

Usage:

$(function() {
  $(SELECTOR).watermark(OPTIONS);
});

Options

Name Type Default Description
path String 'watermark.png' Path contains images used as a watermark, can use base64 image.
text String '' Text used as a watermark.
textWidth Number 130 Text width of frame surrounds, units: px.
textSize Number 12 Font size of text, units: px.
textColor String 'white' Text color, you can use HEX or RGBA color codes.
textBg String 'rgba(0, 0, 0, 0.4)' Background color, you can use HEX or RGBA color codes.
gravity String 'se' The position of the watermark on the image (nw, n, ne, w, e, sw, s, se, c).
opacity Number 0.7 The transparency of watermark, the value between 0 and 1.
margin Number 10 Distance from watermark to edge of image.
outputWidth Number 'auto' Image width after adding watermark, units: px or use 'auto'.
outputHeight Number 'auto' Image height after adding watermark, units: px or use 'auto'.
outputType String 'jpeg' Image format after adding watermark, You can use one of three types (jpeg, png, webp).
done Function function(imgURL){this.src=imgURL;} Called after image with watermark is created.
fail Function function(){} Called after an error of images is occurring.
always Function function(){} Called when processing finishes (done and fail).

Note:

  1. If you use the text parameter, path parameter will be disabled. The watermark will be created from the text you type in text parameter.
  2. In the outputType parameter, webp format only works on the Chrome browser. With other browsers, it will return the png format. Should avoid use png format, because image quality not much higher, but the output image size is quite large.

Examples

Basic usage

<img class="img_awesome" src="img/1.jpg" alt="" />
<img class="img_awesome" src="img/2.jpg" alt="" />
<img class="img_awesome" src="img/3.jpg" alt="" />
$(function() {
  $('.img_awesome').watermark();
});

With this usage, you need put watermark.png image in the root directory. You can replace it by using the path parameter with an URL image or base64 image.

$(function() {
  $('.img_awesome').watermark({
    path: 'http://i.imgur.com/LcpZHu5.png'
  });
});

Choose output image size

For example, limit the maximum width is 500px.

$(function() {
  $('.img_awesome').watermark({
    outputWidth: 500
  });
});

You can also limit the height of image with outputHeight parameter. Should not use 2 size parameters simultaneously, because it can distort your image. Should only use a parameter, it will adjust the remaining parameter with image ratio.

Use text as watermark

Like 9gag style.

$(function() {
  $('.img_awesome').watermark({
    text: 'GOOGLE.COM',
    textWidth: 100,
    gravity: 'w',
    opacity: 1,
    margin: 12
  });
});

Use image URL

If you use the image URL, and you just want to export the image URL (added watermark), you can use the following ways:

One image

$(function() {
    $('<img>', {
        src: 'http://i.imgur.com/AAPx3rB.jpg'
    }).watermark({
        done: function (imgURL) {
            console.log(imgURL);
        }
    });
});

Multiple images

$(function() {
    var inputImages = ['http://i.imgur.com/AAPx3rB.jpg', 'http://i.imgur.com/39dfdPw.jpg', 'http://i.imgur.com/3OfclQY.jpg'];

    var outputImages = [];

    var defer = $.Deferred();
    $.when(defer).done(function () {
        console.log(outputImages);
    });

    $.each(inputImages, function (i, v) {
        $('<img>', {
            src: v
        }).watermark({
            done: function (imgURL) {
                outputImages[i] = imgURL;
                if (i + 1 === inputImages.length) {
                    defer.resolve();
                }
            }
        });
    });
});

License

MIT License © lelinhtinh

FOSSA Status

watermark's People

Contributors

bitdeli-chef avatar fossabot avatar lelinhtinh avatar reddo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

watermark's Issues

Gravity center

This plugin is missing gravity center.

                        case 'center':
                            gLeft = w / 2 - wmW / 2;
                            gTop = h / 2 - wmH / 2;
                            break;

TypeError: $(...).watermark is not a function

Hi,

I added your JS, CSS and html code to rails project.

Here is my code with only commenting initial 3 lines as below.

$('document').ready(function() {

 // if (!window.JpegCamera) return;
 // if (!JpegCamera.canvas_supported()) return;
//  if (!$.fn.watermark) return;

  var camera = new JpegCamera("#camera", {
    shutter_mp3_url: 'https://amw.github.io/jpeg_camera/dist/shutter.mp3',
    shutter_ogg_url: 'https://amw.github.io/jpeg_camera/dist/shutter.ogg'
  }).ready(function() {

    $('#take_snapshot').click(function() {
      var snapshot = camera.capture();

      snapshot.get_canvas(function(canvas) {
        var src = canvas.toDataURL('image/jpeg');

        $('<img>', {
          src: src
        }).watermark({
          text: 'GOOGLE.COM',
          textSize: 30,
          textWidth: 230,
          gravity: 'w',
          opacity: 0.6,
          margin: 12,

          done: function(imgURL) {
            $('#snapshot').attr('src', imgURL);
          },
          fail: function() {
            alert('ERROR!');
          }
        });
      });
    });

It is unable to capture the snapshot due to watermark issue as below in the screenshot.

screenshot from 2018-03-12 14-22-18

adding watermark to image before upload

Hi,

I am trying to use watermark with jpeg_camera project.

I have added code as below. Trying to get image with watermark and not working.

I modified the code of app(https://github.com/amw/jpeg_camera_rails_demo) as below but not working.

Please help me to resolve this issue.

added jquery.watermark to application.js
//= require jquery.watermark

modified the demo.js as below

var upload_snapshot = function() {       
var api_url = "/images";       
 clear_upload_data();      
 $("#loader").show();     
  $("#upload_snapshot").prop("disabled", true);      
  var snapshot = $(".item.selected").data("snapshot");      
  snapshot.get_blob(callback, mime_type = "image/jpeg");       
   function callback(blob) {      
       $('<img>', {
         src: blob,      
         text: 'GOOGLE.COM GOOOOGLE'    
     }).watermark({        
         done: function (imgURL) {        
           console.log(imgURL);      
        }    
     });    
  }      
  snapshot.upload({api_url: api_url}).done(upload_done).fail(upload_fail);   
  };

Thanks.

The plugin works only once

First of all, your plugin is incredibly and very very fast!!! Thanks for that!!!

Well, the problem:
I'm using your plugin with a page that capture one or more images from a input tag (the(is) image(s) are loaded on the page on the fly, i'm not using images from server) and apply the watermark to them. The page lets the user the option to edit/rotate the original image loaded, and than apply once more the watermark.
The process starts when a button is clicked and all works fine, the problem is:
If the user click the button more times (when the user change the original image ), the process do not starts again, that is, the water mark is not applied on the same image!

My code is below:


$("#makeWaterMarkButton").on("click",function(){
      createWaterMark("","","","img/watermark/logo.png");
});


function createWaterMark(position,opacity,className,path){                    
      if(position == "") position = "se";
      if(opacity == "") opacity = 0.8;
      if(className == "") className = "watermark";
      if(path == "") path = "img/watermark/logo_ananeriday.png";

      $("."+className).watermark({
            path: path,
            opacity: opacity,
            gravity: position,
            margin: 0
      });
}

Question: full width/height watermark

Hi,

Plugin looks nice, but I have a question: Is there a way to set the watermark to be full width/height of the image?

I would provide a png larger than the watermarked image and I would like it to be resized to overlay the image completely. Both images would be square.

Also: does the plugin accept svg as the watermark image?

Please add support for External images

Getting following error for external images:
"Origin has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."

2 images in different positions

Hi,

I have 2 images to insert as watermark, but i need to insert one at top-right and another bottom-left, how can I do this ?

stopped working with Chrome Version 65.0.3325.181

Hello.

All of a sudden, It has stopped working on chrome. The 'done' function is called but imgURL has no data. Kindly help. Thanks.

done: function (imgURL) {
           console.log("DEBUG: generated watermarkfile=", imgURL);
}

DEBUG: generated watermarkfile=data:,

Gif is not animating now

I am not sure if this is an issue, consider it as a doubt. I tried it with an animated gif, the anime lost it's animated behaviour after watermark.

Any solution for this ?

URL is changing, original URL,

Hi

This plugin good but for SEO purpose this plugin have issue because in view source changing the image URL which affect on image indexing and SEO. Any solution for this they keep original URL or maintain this own url file name for indexing ?

Thanks

gravity center

why don't you add "gravity - center" on line number 246 in jquery.watermark.js file with :

case 'c': // Center
gLeft = w / 2 - wmW / 2;
gTop = (h - wmH) / 2;
break;

and thanks for your plugin.
best regards

how i add multi text

hello baivong, thanks for this amazing and easy plugin
can i add multi text ? each text will appear in different position on the same image

.data() issue

Not 100% sure what the issue needs to be resolved. Might take me a bit to find a solution, as I am still learning the language.

As a user, I am looking to add watermarks to an image using the URI inline. The first time I add a watermark, the URI is created and I see an image with a watermark. The second time I repeat this process, I have the same results. However, on the third attempt to add a watermark to the image, nothing appears. No new URI is created. Any further attempts after this repeat the results of the third attempt.

Stepping through the process, when an unsuccessful attempt happens, line 280 in jQuery.Watermark.js seems to find existing data. As such, line 281 is never run. I have attached screenshots of my setup as well.

image

image

Not working!

I did everything but does not work. I see your demo, it does not work.

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.