Logo

dev-resources.site

for different kinds of informations.

Gif Widget : "Text Watermark"

Published at
8/16/2022
Categories
template
tool
gif
javascript
Author
egfx
Categories
4 categories in total
template
open
tool
open
gif
open
javascript
open
Author
4 person written this
egfx
open
Gif Widget : "Text Watermark"


The template includes everything you need to create a toolbar app in gif.com.ai

The Text Watermark widget creates a semi permanent watermark on the right corner of your gif. You can pin this widget onto your toolbar and activate it on demand. The template to the "Text Watermark" widget is also included at the bottom of this post.


Widget Teardown:

The watermark library adds the actual watermark to the gif. The widget just fires up a modal so the user could enter in some text.

Image description

A watermark based on the text the user entered is then implanted onto the canvas...

Image description


Comes in two parts:

1) JS Context

A self executing anonymous function sets off the dialog modal to enter in the text. An event listener that listens to the canvas:resize event is created so the label can be re-oriented whenever the canvas is resized.


(async function(){
    const { value: text } = await Swal.fire({
        title: 'Text Watermark',
        text: 'Text you want to watermark on your gif.',
        input: 'text',
        showConfirmButton: true,
        allowOutsideClick: false,
        allowEscapeKey: false,
        inputLabel: 'Watermark',
        inputPlaceholder: 'Type your text here...',
        inputAttributes: {
          'aria-label': 'Type your text here'
        },
        showCancelButton: true
      });
      if (text) {
          genWatermark(watermark, text)
          document.addEventListener('canvas:resize', function(){
              genWatermark(watermark, text)
          });
      }
})();
Enter fullscreen mode Exit fullscreen mode

The actual watermark generation and placement is done through a function call. This function gets called in two places, once after the text is entered into the box and every time the canvas is resized.

function genWatermark(watermark, text){
    let wm = new Image($('#gifcanvas').width(), 
    $('#gifcanvas').height());
    $(wm).css('pointer-events', 'none');
    watermark([wm])
    .image(watermark.text.lowerRight(text, '48px Josefin Slab', '#fff', 0.5))
    .then(function (img) {
        img.id = 'watermark';
        $('#watermark').remove();
        $('#gifcanvas').prepend(img).find('#watermark').zIndex(2147483647).css('pointer-events', 'none');
    });
}
Enter fullscreen mode Exit fullscreen mode

2) Settings Context

The mode property with the value of pin tells our gif webtop that this item belongs in the toolbar. Similarly the thumbnail property sets an icon for the widget in the toolbar.

{
    title: "Text Watermark",
    description: "Place a text watermark on the right corner.",
    autorun: false,
    mode: "pin",
    thumbnail: "https://i.imgur.com/lRMAZTM.png"
}
Enter fullscreen mode Exit fullscreen mode

Check out the "Text Watermark" widget template below.

Open template

gif Article's
30 articles in total
Favicon
It’s Probably Worth Converting that GIF to an Animated WebP
Favicon
GIF App Development – How to Develop GIF Encoding
Favicon
GIF App Development – Challenges & Tips
Favicon
Happy Birthday Gifs
Favicon
Bring Your Drawings to Life: A Step-by-Step Guide to Animation with Pivot Animator 5
Favicon
Tool Breakdown : Show/Hide Timer
Favicon
How to convert your screen recordings to GIF on macOS?
Favicon
Adding Gif Canvas Features : Grid Snap
Favicon
Create GIFs Like a Pro with Our Professional-Grade Gif Maker
Favicon
Animated texture library for react-three-fiber available in react's hooks base
Favicon
How to Add GIFs to Your Dev.to Articles with Cloudinary
Favicon
Peek: Simplify Screen Recordings
Favicon
Contributions can lead to unexpected solutions
Favicon
How does the GIF function works in Whatsapp and Telegram?
Favicon
Linking to a Giphy gif
Favicon
Creating animated gifs from your terminal
Favicon
Gif Widget : "Paint it Black"
Favicon
Gif Widget : "Text Watermark"
Favicon
Gif Widget : "Markdown Meme Maker"
Favicon
Thinking in "GIF" with React
Favicon
React JS Gif : Starter Kit
Favicon
What's the best way how to a movie file convert to an animation image(animation gif or animation png or webP)?
Favicon
Como fazer GIF animado com Python
Favicon
FFmpeg: Convert video to gif
Favicon
Gifit: Convert Screen Recordings to easy-to-share Animated gifs
Favicon
How do you deal with large GIF sizes?
Favicon
Search For GIFs Without Leaving Your Terminal
Favicon
How to make a video with 9VAe
Favicon
How to make Barrel Fish animation from SVG : 9VAe
Favicon
Converting GIF to MP4

Featured ones: