Skip to main content
PESDK/Android/Guides
Language:

Watermark

Watermark

PhotoEditor SDK supports several configuration options for WatermarkSettings allowing flexible adaptation to different needs and use cases.

If adding the watermark is the only editing operation to be performed, please set the output mode to EXPORT_ALWAYS to export the photo with the watermark.

Watermark image#

Here, we set the image for the watermark by providing an ImageSource created from a resource drawable. Alternatively, you can also create it from a File or a Uri.

The watermark itself is not processed, so to achieve the effect of transparency, make sure that your input image supports that (use a PNG file with an alpha channel).

Size#

The default size of the watermark relative to the smaller side of the photo is 20%. In this example, we set it to 30%.

Inset#

The default inset of the watermark relative to the smaller side of the photo is 5%. In this example, we set it to 10%.

Alignment#

The default alignment of the watermark is bottom left. In this example, we set it to bottom right.

File:
class PhotoWatermark(private val activity: AppCompatActivity) : Example(activity) {
override fun invoke() {
// In this example, we do not need access to the Uri(s) after the editor is closed
// so we pass false in the constructor
val settingsList = PhotoEditorSettingsList(false)
// Set the source as the Uri of the image to be loaded
.configure<LoadSettings> {
it.source = activity.resourceUri(R.drawable.la)
}
settingsList.configure<WatermarkSettings> {
it.image = ImageSource.create(R.drawable.imgly_watermark)
// By default, the value of size is 0.2. For this example, we change it to 0.3
it.size = 0.3f
// By default, the value of inset is 0.05. For this example, we change it to 0.1
it.inset = 0.1f
// By default, the alignment for the watermark is bottom left. For this example, we change it to bottom right
it.alignment = WatermarkSettings.Alignment.BOTTOM_RIGHT
}
// Start the photo editor using PhotoEditorBuilder
// The result will be obtained in onActivityResult() corresponding to EDITOR_REQUEST_CODE
PhotoEditorBuilder(activity)
.setSettingsList(settingsList)
.startActivityForResult(activity, EDITOR_REQUEST_CODE)
// Release the SettingsList once done
settingsList.release()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
intent ?: return
if (requestCode == EDITOR_REQUEST_CODE) {
// Wrap the intent into an EditorSDKResult
val result = EditorSDKResult(intent)
when (result.resultStatus) {
EditorSDKResult.Status.CANCELED -> showMessage("Editor cancelled")
EditorSDKResult.Status.EXPORT_DONE -> showMessage("Result saved at ${result.resultUri}")
else -> {
}
}
}
}
}