• Stars
    star
    417
  • Rank 103,829 (Top 3 %)
  • Language
    Java
  • Created over 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ“ซ RubberStamp is an Android library that makes it easy for you to add a watermark to your images.

RubberStamp ๐Ÿ“ซ

Feature Image

RubberStamp is an Android library that makes it easy for you to watermark your images.

Screenshots

Features

  • Add a watermark to your images.
  • It can be text or another image.
  • Multiple ways and features to customize how the watermark looks including attributes like font, color, opacity, size, shadow properties, etc.
  • Flexible API that has multiple pre-defined options to get started quickly.
  • Ability to tile your watermark across an image.

Setup

The library is pushed to Maven Central as an AAR, so you just need to add the following to your build.gradle file:

dependencies {
    compile โ€˜com.vinaygaba:rubberstamp:1.0.0โ€™
}

Usage

Using RubberStamp is extremely easy.

First, define the characteristics of your watermark using RubberStampConfig

RubberStampConfig config = new RubberStampConfigBuilder()
              .base(R.drawable.lenna)
              .rubberStamp("Watermark")
              .rubberStampPosition(RubberStamp.CENTER)
              .alpha(100)
              .margin(30, 30)
              .rotation(-45)
              .textColor(Color.BLACK)
              .textBackgroundColor(Color.WHITE)
              .textShadow(0.1f, 5, 5, Color.BLUE)
              .textSize(90)
              .textFont("fonts/champagne.ttf");
              .build();

That's all that is needed really. All you need to do next is just pass this config to the addStamp method of the RubberStamp class and voila!

RubberStamp rubberStamp = new RubberStamp(this);
rubberStamp.addStamp(config);

Attribute Usage & Documentation

All the attributes listed below are part of RubberStampConfig.

I. base

Use this to set the base image on top of which the watermark will be drawn. This can be a bitmap or a drawable.

config.base(bitmap);

config.base(R.id.image);
II. rubberStamp

The rubberstamp is the actual watermark that will be drawn on top of the base image. This can either be a bitmap or a string.

// String watermark
config.rubberStamp("Watermark" );

// Bitmap watermarkBitmap
config.rubberStamp(bitmap);

If you want to use a drawable, convert it to a bitmap and use that. You would do that using:

Bitmap bitmap = BitmapFactory.decodeResources(getResources(), R.drawable.logo);
III. rubberStampPosition

The library provides 9 pre defined positions to display the location of the rubberstamp. They are as follows:

TOP_LEFT
TOP_CENTER
TOP_RIGHT
BOTTOM_LEFT
BOTTOM_CENTER
BOTTOM_RIGHT
CENTER_LEFT
CENTER
CENTER_RIGHT

// RubberStampPosition position
config.rubberStampPosition(RubberStampPosition.BOTTOM_RIGHT);

In additon, if you would like to specify the exact position of the rubberstamp, you can pass the the RubberStampPosition to be CUSTOM and use the following constructor to specify the position.

// RubberStampPosition position, int xCoordinate, int yCoordinate
config.rubberStampPosition(RubberStampPosition.CUSTOM, 100, 100);

There is another special position, TILE that you can use in order to tile the rubberstamp across the base image. This is a fairly common use case for watermarking software so it made sense for the library to support it. You can use it in the following way:

// RubberStampPosition position
config.rubberStampPosition(RubberStampPosition.TILE);

IV. alpha

Use alpha to change the opacity of your rubberstamp. It accepts an int value between 0 and 255.

//int alpha
config.alpha(255);

V. rotation

Rotation does exactly what you'd imagine it to: it rotates your rubberstamp. It expects a float value to be passed to it.

config.rotation(45);
config.rotation(-45);

VI. margin

Margin lets you specify the x & y offset for your rubberstamp after you have selected its RubberStampPosition. This is to give the user the ability to position his rubberstamp at a more precise location if the defaults RubberStampPosition presets are not good enough.

// int xMargin, int yMargin
config.margin(-30, 30);

Text RubberStamp specific attributes

There are some additional attributes that this library provides when you pass a String as the RubberStamp. These attributes won't have any side effects when you pass a bitmap as a rubberstamp and will be disregarded. Most of them are pretty self explanatory.

VII. textColor

Sets the text color of the rubberstamp.

config.textColor(Color.parseColor("#FFB6C1"));

VIII. textBackgroundColor

This lets you specify a background color for your text rubberstamp.

Note This attribute does not work when the position is set to RubberStampPosition.TILE

//int color
config.textBackgroundColor(Color.WHITE);

IX. textSize

Sets the size of the text rubberstamp.

//int size
config.textSize(40);

X. textShader

This lets you specify a custom shader that you can use to customize the watermark. Honestly, the sky is the limit when it comes to Shaders. Here is an example shader that paints my watermark in rainbow colors.

RubberStamp rubberStamp = new RubberStamp(this);
int[] rainbow = {Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE, Color.MAGENTA};
Shader shader = new LinearGradient(0, 0, 0, logo.getWidth(), rainbow,
        null, Shader.TileMode.MIRROR);
Matrix matrix = new Matrix();
matrix.setRotate(90);
shader.setLocalMatrix(matrix);

//set the shader
config.textShader(shader);

XI. textShadow

This lets you specify a shadow for your text rubberstamp. Note: No shadow will be displayed if the blur radius is set to 0. This is how the paint API in Android behaves underneath as well.

//float blurRadius, float xOffset, float yOffset, int color
config.textShadow(1.0f, 5, 5, Color.BLUE);

XII. textFont

Use this to specify a custom font for your text rubberstamp.

//String fontpath
config.textFont("fonts/champagne.ttf");

Credits

Author: Vinay Gaba ([email protected])

Follow me on Google+ Follow me on Twitter Follow me on LinkedIn

License

Copyright 2017 Vinay Gaba

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

Learn-Jetpack-Compose-By-Example

๐Ÿš€ This project contains various examples that show how you would do things the "Jetpack Compose" way
Kotlin
2,910
star
2

CreditCardView

๐Ÿ’ณ CreditCardView is an Android library that allows developers to create the UI which replicates an actual Credit Card.
Java
786
star
3

Ultimate-String-Array-List

๐Ÿงต A comprehensive list of string-arrays that you may need on a daily basis when developing an Android app
154
star
4

JetpackCompose.app

๐Ÿš€ The best source on the interwebs for all things Jetpack Compose!
TypeScript
76
star
5

Traveller

โœˆ๏ธ Add a map on your site with every place that you have visited!
HTML
22
star
6

Droidcon-SF-2019-Architecture-Agnostic-UI-Development

๐Ÿ—๏ธ Architecture Agnostic UI Development
Kotlin
7
star
7

SOS

This is an SOS application.The user has to enter a mobile number in the settings and save it. When the user presses the SOS button,the number that he entered gets an SMS with his current location.
Java
5
star
8

CopyCat

Save important texts/snippets in your Command Line! ๐Ÿ˜บ
JavaScript
5
star
9

PAL

PAL: PDF Automation Language
OCaml
2
star
10

LetsHobee

Work In Progress
Java
2
star
11

BrailleIn2

An Android application made for the visually impaired which makes their life easy.
1
star
12

vinaygaba2.github.io

HTML
1
star
13

voice

It was used to test the Voice Recognition feature of android.The possible intrepretations of what the user spoke is displayed in a list.
Java
1
star
14

COMS-4771-Machine-Learning

Repo to have all the assignments that I wrote for the machine learning class
MATLAB
1
star
15

TextToAudio

A text to audio app.The user enters the text that he wants the app to speak.The pitch can be adjusted as well.
Java
1
star