Introduction
lhwatermark is a lightweight Swift library for adding watermarks to images. It provides a simple and efficient way to add text or image watermarks to your images, giving you the ability to customize their appearance and placement.
Features
- Supports adding text and image watermarks
- Customizable watermark appearance
- Flexible placement options
- Simple and efficient implementation
- Works with popular image formats such as JPEG and PNG
Installation
To install lhwatermark, simply follow these steps:
- Open your Xcode project
- Go to File -> Swift Packages -> Add Package Dependency
- Enter the repository URL:
https://github.com/[username]/lhwatermark.git
- Select the desired version or branch
- Click Next, then Finish
Usage
lhwatermark is easy to use. Here’s an example of how to add a text watermark:
import lhwatermark
let image = UIImage(named: "example.jpg")
let watermark = Watermark(text: "Confidential")
let watermarkedImage = watermark.apply(to: image)
You can also add an image watermark:
import lhwatermark
let image = UIImage(named: "example.jpg")
let watermark = Watermark(image: UIImage(named: "watermark.png")!)
let watermarkedImage = watermark.apply(to: image)
Customization
lhwatermark provides several customization options to control the appearance and placement of your watermarks. Here are some examples:
Customizing Text Watermarks
To customize text watermarks, you can modify properties of the Watermark object:
- text: The text content of the watermark.
- font: The font to use for the text.
- color: The color of the text.
- opacity: The opacity of the text.
- size: The size of the text.
Customizing Image Watermarks
To customize image watermarks, you can modify properties of the Watermark object:
- image: The image to use as the watermark source.
- scale: The scale factor of the image.
- opacity: The opacity of the image.
- size: The size of the image.
Placement
You can control the placement of your watermarks using the position
property of the Watermark object. Available options include:
- topLeft
- topRight
- bottomLeft
- bottomRight
- center
Examples
Here are some examples of how to use lhwatermark to create watermarked images:
Example 1: Adding a Text Watermark
import lhwatermark
let image = UIImage(named: "example.jpg")
let watermark = Watermark(text: "Confidential")
watermark.font = UIFont.systemFont(ofSize: 24)
watermark.color = .red
watermark.opacity = 0.5
let watermarkedImage = watermark.apply(to: image)
Example 2: Adding an Image Watermark
import lhwatermark
let image = UIImage(named: "example.jpg")
let watermark = Watermark(image: UIImage(named: "watermark.png")!)
watermark.scale = 0.5
watermark.opacity = 0.8
let watermarkedImage = watermark.apply(to: image)
Conclusion
lhwatermark is a versatile Swift library that allows you to easily add watermarks to your images. It offers powerful customization options and flexible placement choices. Start using lhwatermark in your projects today to enhance your image processing capabilities.