Menu

How to Stamp a Transparent PNG Logo Across a Batch of Photos in Swift
📰

How to Stamp a Transparent PNG Logo Across a Batch of Photos in Swift

DEV Community: mobile·Maxwell·8 days ago
#1aWSYG7X
#devtomobile#devto#dev#spec#uiimage
Reading 0:00
15s threshold

If you need the same logo on thirty photos, the boring bugs show up immediately: the mark looks huge on a 12-megapixel still and timid on a 48-megapixel one, the PNG’s transparent background turns into a grey box, or the edges of the logo go muddy because the alpha channel was applied twice.

This post walks through a small UIKit pipeline that loads a transparent PNG, draws each photo, then draws the logo at a size tied to the photo’s shorter side, inset by a percentage of the frame. I’m writing it from the seat of someone who builds BatchMark, an on-device batch photo app; the batch watermark path is where this idea lives in the product. The code below is a teaching extract, not a dump of the app.

What “the same logo” should mean

People say “put the logo in the corner” and mean three separate decisions:

How large is it, visually? Not “200 pixels,” because 200 pixels is a different object on a 4032-pixel-wide photo than on a 8064-pixel-wide one.

How far is it from the edges?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.