• Stars
    star
    203
  • Rank 186,739 (Top 4 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 12 months ago

Reviews

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

Repository Details

GPU/CPU-based iOS Watermark Library for Image and Video Overlay

About

MediaWatemark is an open source GPU/CPU-based iOS watermark library for overlays adding to images or video content. It has simple interface and straightforward functionality.

Overview

Simple & Universal

MediaWatemark is easy to install and integrate into any iOS project. It processes the wide variety of tasks and goes perfectly for overlaying views and texts over the videos or other images.

Light Code

MediaWatemark consists of light code and makes it easy to overlay one image over another, or do the same with the video content.

Easy Installation

Before using the library in your work, you may run the example project, I'm sharing below. When you are ready to use it, just follow the short and easy Installation tip below.

Installation

CocoaPods

MediaWatermark is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "MediaWatermark"

Carthage

To integrate MediaWatermark into your Xcode project using Carthage, specify it in your Cartfile:

github "rubygarage/media-watermark" ~> 0.4

Run carthage update to build the framework and drag the built MediaWatermark.framework into your Xcode project.

Requirements

iOS: 9.0+
Swift: 5.0
CocoaPods: for iOS
Processing Concept: GPU & CPU

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Usage

Adding several images over the other image

To add two images with different coordinates over the third image, you may use code like the following. The images are placed according to the coordinates you set in the code.

if let item = MediaItem(url: url) {
    let logoImage = UIImage(named: "rglogo")
            
    let firstElement = MediaElement(image: logoImage!)
    firstElement.frame = CGRect(x: 0, y: 0, width: logoImage!.size.width, height: logoImage!.size.height)
            
    let secondElement = MediaElement(image: logoImage!)
    secondElement.frame = CGRect(x: 150, y: 150, width: logoImage!.size.width, height: logoImage!.size.height)
                        
    item.add(elements: [firstElement, secondElement])
            
    let mediaProcessor = MediaProcessor()
    mediaProcessor.processElements(item: item) { [weak self] (result, error) in
    	// handle result            
    }
}

Adding an image and text over the image

The next script template will work in case if you need to render an image and text over the other image:

let item = MediaItem(image: image)
        
let logoImage = UIImage(named: "logo")
        
let firstElement = MediaElement(image: logoImage!)
firstElement.frame = CGRect(x: 0, y: 0, width: logoImage!.size.width, height: logoImage!.size.height)
                
let testStr = "Test Attributed String"
let attributes = [ NSForegroundColorAttributeName: UIColor.white, NSFontAttributeName: UIFont.systemFont(ofSize: 35) ]
let attrStr = NSAttributedString(string: testStr, attributes: attributes)
        
let secondElement = MediaElement(text: attrStr)
secondElement.frame = CGRect(x: 300, y: 300, width: logoImage!.size.width, height: logoImage!.size.height)
        
item.add(elements: [firstElement, secondElement])
        
let mediaProcessor = MediaProcessor()
mediaProcessor.processElements(item: item) { [weak self] (result, error) in
    self?.resultImageView.image = result.image
}

Adding an image and text over the video

To add an image and text over the video you may refer the following code extract:

if let item = MediaItem(url: url) {
	let logoImage = UIImage(named: "logo")
            
	let firstElement = MediaElement(image: logoImage!)
	firstElement.frame = CGRect(x: 0, y: 0, width: logoImage!.size.width, height: logoImage!.size.height)
            
	let testStr = "Attributed Text"
	let attributes = [ NSForegroundColorAttributeName: UIColor.white, NSFontAttributeName: UIFont.systemFont(ofSize: 35) ]
	let attrStr = NSAttributedString(string: testStr, attributes: attributes)
            
	let secondElement = MediaElement(text: attrStr)
	secondElement.frame = CGRect(x: 300, y: 300, width: logoImage!.size.width, height: logoImage!.size.height)
            
    item.add(elements: [firstElement, secondElement])
            
    let mediaProcessor = MediaProcessor()
    mediaProcessor.processElements(item: item) { [weak self] (result, error) in
        self?.videoPlayer.url = result.processedUrl
        self?.videoPlayer.playFromBeginning()
    }
}

Image processing by Metal

MediaWatermark provides five filters for images:

  • Color filter
  • Sepia
  • Blur
  • Sobel
  • Threshold

To add filter over image:

let item = MediaItem(image: image)

let colorFilter = ColorFilter()
colorFilter.r = 1
colorFilter.g = 1
colorFilter.b = 0
        
item.applyFilter(mediaFilter: colorFilter)
        
let logoImage = UIImage(named: "logo")
        
let firstElement = MediaElement(image: logoImage!)
firstElement.frame = CGRect(x: 0, y: 0, width: logoImage!.size.width, height: logoImage!.size.height)
        
let secondElement = MediaElement(image: logoImage!)
secondElement.frame = CGRect(x: 100, y: 100, width: logoImage!.size.width, height: logoImage!.size.height)
        
item.add(elements: [firstElement, secondElement])
        
let mediaProcessor = MediaProcessor()
mediaProcessor.processElements(item: item) { [weak self] (result, error) in
    self?.resultImageView.image = result.image
}

Please note that filters are currently used for image assets only.

Author

Sergey Afanasiev

Getting Help

[email protected]

License

MediaWatermark is available under the MIT license. See the LICENSE file for more info.


RubyGarage Logo

RubyGarage is a leading software development and consulting company in Eastern Europe. Our main expertise includes Ruby and Ruby on Rails, but we successfully employ other technologies to deliver the best results to our clients. Check out our portfolio for even more exciting works!

More Repositories

1

collection-view-layouts

A library that implements custom flow layouts for iOS apps
Swift
662
star
2

emotion-rating-view

A library for animated rating view in Android apps.
Kotlin
302
star
3

shopapp-android

ShopApp is an application that transfers an online store into a mobile app
Kotlin
148
star
4

react-native-firebase-chat

This repository contains the source code for a simple chat application built with React Native (frontend) and Firebase (backend).
JavaScript
148
star
5

shopapp-ios

ShopApp is an application that transfers an online store into a mobile app
Swift
114
star
6

detectify

Detectify is a gem for multi-tenant Rack apps, to help you retrieve domain and subdomain-related data from a database.
Ruby
79
star
7

boilerplate

This repo will help you to build quickly your Rails API with Trailblazer and friends.
Ruby
57
star
8

Design-Patterns-in-Swift

This is a repository for our article about design patterns in the Swift programming language https://rubygarage.org/blog/swift-design-patterns
Swift
53
star
9

shopapp-shopify-ios

A Shopify provider for a ShopApp for iOS application
Swift
52
star
10

shopapp-shopify-android

A Shopify provider for a ShopApp for Android application
Kotlin
51
star
11

authorize-me

Authorization with social networks
Swift
44
star
12

rubygarage.github.com

This repository contains slides for Ruby/Ruby on Rails courses from RubyGarage
CSS
44
star
13

nextjs6-graphql-client-tutorial

Demo app
JavaScript
43
star
14

mvc-components-refactoring-in-rails

Code examples of MVC components refactoring in Rails from RubyGarage to SitePoint
Ruby
16
star
15

arkit-example

This repository is created for the article https://rubygarage.org/blog/create-augmented-reality-app-for-ios-11
Swift
12
star
16

shareconomy

Ruby
7
star
17

holtwinters

JavaScript
4
star
18

graphql_meetup

Ruby
4
star
19

graphql-tutorial

Ruby
3
star
20

monitorbit

Ruby
2
star
21

aws-practice

2
star
22

odbcimporter

Go
1
star
23

rubyhub

Ruby implementation for hub soft
Ruby
1
star
24

vertigo-rtm-outdated

Ruby
1
star
25

frontend-internship-template

JavaScript
1
star
26

bootstrap-store-theme

HTML
1
star
27

interview-rails

Ruby
1
star
28

action_controller_audit_trail

Action Controller Audit Trail gem
Ruby
1
star
29

trailblazer-courses

Ruby
1
star
30

ios-application-testing

This repository demonstrates how to set up your iOS project for automated testing. We created this repo as a demo project for the article https://rubygarage.org/blog/testing-ios-app .
Swift
1
star
31

sentryimporter

Go
1
star
32

interview-vuejs

Vue
1
star
33

terraform-boilerplate

HCL
1
star
34

interview-react-and-scss

JavaScript
1
star