Skip to content

Commit 7a476ac

Browse files
authored
feat: text background border radius (#139)
1 parent 1604e3e commit 7a476ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+492
-128
lines changed

README.0.9.2.MD

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ Add text or icon watermark to your images
55
## sample
66

77
<p>
8-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/IOSMarker.gif" width='200'>
9-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/AndroidMarker.gif" width='200'>
10-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/shadow_bg_fit.png" width='200'>
11-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/shadow_bg_sx.png" width='200'>
12-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/shadow.png" width='200'>
13-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/shadow_bg_sy.png" width='200'>
8+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/IOSMarker.gif" width='200'>
9+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/AndroidMarker.gif" width='200'>
10+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/shadow_bg_fit.png" width='200'>
11+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/shadow_bg_sx.png" width='200'>
12+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/shadow.png" width='200'>
13+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/shadow_bg_sy.png" width='200'>
1414
</p>
1515

1616
## Installation

README.MD

Lines changed: 91 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div align="center">
22
<a href="https://jimmydaddy.github.io/react-native-image-marker/" title="react native image marker">
3-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/icon.png" alt="react native image marker Logo" width="150" />
3+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/icon.png" alt="react native image marker Logo" width="150" />
44
</a>
55
<a href="https://jimmydaddy.github.io/react-native-image-marker/"><h1 style="color: #424E6D">react native image marker</h1></a>
66
<h6>Add text or icon watermarks to images</h6>
@@ -29,13 +29,15 @@
2929
* text align
3030
* padding
3131
* relative position
32+
* background border radius
3233
* Compatible with both Android and iOS
3334

3435
## Sample
3536

36-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/IOSMarker.gif" width='150'>
37-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/AndroidMarker.gif" width='150'>
38-
37+
<p>
38+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/IOSMarker.gif" width='150'>
39+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/AndroidMarker.gif" width='150'>
40+
</p>
3941

4042
## Usage
4143

@@ -53,7 +55,7 @@
5355
##### Sample
5456

5557

56-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/shadow_bg_fit.png" width='150'>
58+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/shadow_bg_fit.png" width='150'>
5759

5860

5961
##### Example
@@ -110,7 +112,7 @@ Marker.markText(options);
110112
##### Sample
111113

112114

113-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/shadow_bg_sx.png" width='150'>
115+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/shadow_bg_sx.png" width='150'>
114116

115117
##### Example
116118

@@ -165,7 +167,7 @@ Marker.markText(options);
165167
##### Sample
166168

167169

168-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/shadow_bg_sy.png" width='150'>
170+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/shadow_bg_sy.png" width='150'>
169171

170172
##### Example
171173

@@ -211,6 +213,71 @@ ImageMarker.markText(options);
211213

212214
```
213215

216+
#### Text background border radius
217+
218+
##### API
219+
220+
221+
[TextBackgroundType.cornerRadius](https://jimmydaddy.github.io/react-native-image-marker/enums/TextBackgroundType.html#cornerRadius)
222+
223+
##### Sample
224+
225+
226+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/textbgcornerradius.png" width='150'>
227+
228+
##### Example
229+
230+
231+
```typescript
232+
import Marker, { Position } from "react-native-image-marker"
233+
···
234+
const options = {
235+
// background image
236+
backgroundImage: {
237+
src: require('./images/test.jpg'),
238+
scale: 1,
239+
},
240+
watermarkTexts: [{
241+
text: 'text marker normal',
242+
positionOptions: {
243+
position: Position.center,
244+
},
245+
style: {
246+
color: '#FC0700',
247+
fontSize: 30,
248+
fontName: 'Arial',
249+
shadowStyle: {
250+
dx: 10,
251+
dy: 10,
252+
radius: 10,
253+
color: '#008F6D',
254+
},
255+
textBackgroundStyle: {
256+
padding: '10%',
257+
color: '#0fA',
258+
cornerRadius: {
259+
topLeft: {
260+
x: '20%',
261+
y: '50%',
262+
},
263+
topRight: {
264+
x: '20%',
265+
y: '50%',
266+
},
267+
},
268+
},
269+
},
270+
}],
271+
scale: 1,
272+
quality: 100,
273+
filename: 'test',
274+
saveFormat: ImageFormat.png,
275+
maxSize: 1000,
276+
};
277+
ImageMarker.markText(options);
278+
279+
```
280+
214281
#### Text with shadow
215282

216283
##### API
@@ -221,7 +288,7 @@ ImageMarker.markText(options);
221288
##### Sample
222289

223290

224-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/shadow.png" width='150'>
291+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/shadow.png" width='150'>
225292

226293
##### Example
227294

@@ -273,7 +340,7 @@ Marker.markText(options);
273340
##### Sample
274341

275342

276-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/multipletexts.png" width='150'>
343+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/multipletexts.png" width='150'>
277344

278345
##### Example
279346

@@ -326,9 +393,9 @@ Marker.markText({
326393

327394

328395
<p>
329-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/rotatetexts_1.png" width='150'>
330-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/textswihoutbg.png" width='150'>
331-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/rotatetexts.png" width='150'>
396+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/rotatetexts_1.png" width='150'>
397+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/textswihoutbg.png" width='150'>
398+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/rotatetexts.png" width='150'>
332399
</p>
333400

334401
##### Example
@@ -388,7 +455,7 @@ Marker.markText({
388455
##### Sample
389456

390457

391-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/imagewatermark.png" width='150'>
458+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/imagewatermark.png" width='150'>
392459

393460
##### Example
394461

@@ -421,7 +488,7 @@ Marker.markImage({
421488

422489

423490

424-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/multiple_icon_markers.png" width='150'>
491+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/multiple_icon_markers.png" width='150'>
425492

426493

427494
##### Example
@@ -461,8 +528,8 @@ Marker.markImage({
461528

462529

463530
<p>
464-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/rotatebg.png" width='150'>
465-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/rotateimageicon.png" width='150'>
531+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/rotatebg.png" width='150'>
532+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/rotateimageicon.png" width='150'>
466533
</p>
467534

468535
##### Example
@@ -540,7 +607,7 @@ Marker.markText({
540607
##### Sample
541608

542609

543-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/rotateicon.png" width='150'>
610+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/rotateicon.png" width='150'>
544611

545612
##### Example
546613

@@ -569,7 +636,7 @@ Marker.markImage({
569636
##### Sample
570637

571638

572-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/alphabgonly.png" width='150'>
639+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/alphabgonly.png" width='150'>
573640

574641
##### Example
575642

@@ -598,7 +665,7 @@ Marker.markImage({
598665
##### Sample
599666

600667

601-
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/asset/alphicononly.png" width='150'>
668+
<img src="https://raw.githubusercontent.com/JimmyDaddy/react-native-image-marker/master/assets/alphicononly.png" width='150'>
602669

603670
##### Example
604671

@@ -686,6 +753,11 @@ This library use [Fresco](https://github.com/facebook/fresco) to decode image on
686753
If you want to run the example locally, you can do the following:
687754

688755
```bash
756+
757+
git clone git@github.com:JimmyDaddy/react-native-image-marker.git
758+
759+
cd ./react-native-image-marker
760+
689761
# Android
690762
# Open an android emulator or connect a real device at first
691763
yarn example android

android/src/main/java/com/jimmydaddy/imagemarker/ImageMarkerManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ class ImageMarkerManager(private val context: ReactApplicationContext) : ReactCo
8484
} else {
8585
canvas.drawBitmap(
8686
markerBitmap!!,
87-
(Utils.parseSpreadValue(markOpts.x, width) ?: DEFAULT_MARGIN).toFloat(),
88-
(Utils.parseSpreadValue(markOpts.y, height) ?: DEFAULT_MARGIN).toFloat(),
87+
(Utils.parseSpreadValue(markOpts.x, width.toFloat()) ?: DEFAULT_MARGIN),
88+
(Utils.parseSpreadValue(markOpts.y, height.toFloat()) ?: DEFAULT_MARGIN),
8989
markOpts.imageOption.applyStyle()
9090
)
9191
}

android/src/main/java/com/jimmydaddy/imagemarker/base/Constants.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ object Constants {
1515

1616
const val BASE64 = "base64"
1717

18-
const val DEFAULT_MARGIN = 20;
18+
const val DEFAULT_MARGIN = 20f
1919
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.jimmydaddy.imagemarker.base
2+
3+
import com.facebook.react.bridge.ReadableMap
4+
5+
import android.graphics.RectF
6+
7+
data class CornerRadius(val opts: ReadableMap?) {
8+
private var topLeft: Radius? = null
9+
private var topRight: Radius? = null
10+
private var bottomLeft: Radius? = null
11+
private var bottomRight: Radius? = null
12+
private var all: Radius? = null
13+
14+
init {
15+
16+
val iterator = opts?.entryIterator
17+
18+
if (iterator != null) {
19+
while (iterator.hasNext()) {
20+
val entry = iterator.next()
21+
val cornerRadius = entry.value
22+
23+
when (entry.key) {
24+
"topLeft" -> {
25+
if (cornerRadius == null) break
26+
topLeft = Radius(cornerRadius as ReadableMap?)
27+
}
28+
29+
"topRight" -> {
30+
if (cornerRadius == null) break
31+
topRight = Radius(cornerRadius as ReadableMap?)
32+
}
33+
34+
"bottomLeft" -> {
35+
if (cornerRadius == null) break
36+
bottomLeft = Radius(cornerRadius as ReadableMap?)
37+
}
38+
39+
"bottomRight" -> {
40+
if (cornerRadius == null) break
41+
bottomRight = Radius(cornerRadius as ReadableMap?)
42+
}
43+
44+
else -> {
45+
if (cornerRadius == null) break
46+
all = Radius(cornerRadius as ReadableMap?)
47+
}
48+
}
49+
}
50+
}
51+
}
52+
53+
fun radii(rect: RectF): FloatArray {
54+
var mxRadius = 0f
55+
var myRadius = 0f
56+
57+
if (all != null) {
58+
mxRadius = Utils.parseSpreadValue(all!!.x, rect.width())
59+
myRadius = Utils.parseSpreadValue(all!!.y, rect.height())
60+
}
61+
62+
val radii = floatArrayOf(
63+
mxRadius, // topLeftX
64+
myRadius, // topLeftY
65+
mxRadius, // topRightX
66+
myRadius, // topRightY
67+
mxRadius, // bottomRightX
68+
myRadius, // bottomRightY
69+
mxRadius, // bottomLeftX
70+
myRadius // bottomLeftY
71+
)
72+
73+
if (topLeft != null) {
74+
radii[0] = Utils.parseSpreadValue(topLeft!!.x, rect.width())
75+
radii[1] = Utils.parseSpreadValue(topLeft!!.y, rect.height())
76+
}
77+
78+
if (topRight != null) {
79+
radii[2] = Utils.parseSpreadValue(topRight!!.x, rect.width())
80+
radii[3] = Utils.parseSpreadValue(topRight!!.y, rect.height())
81+
}
82+
83+
if (bottomRight != null) {
84+
radii[4] = Utils.parseSpreadValue(bottomRight!!.x, rect.width())
85+
radii[5] = Utils.parseSpreadValue(bottomRight!!.y, rect.height())
86+
}
87+
88+
if (bottomLeft != null) {
89+
radii[6] = Utils.parseSpreadValue(bottomLeft!!.x, rect.width())
90+
radii[7] = Utils.parseSpreadValue(bottomLeft!!.y, rect.height())
91+
}
92+
93+
return radii
94+
}
95+
}

android/src/main/java/com/jimmydaddy/imagemarker/base/ImageOptions.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import com.jimmydaddy.imagemarker.base.Constants.DEFAULT_ALPHA
99
import com.jimmydaddy.imagemarker.base.Constants.DEFAULT_ROTATE
1010
import com.jimmydaddy.imagemarker.base.Constants.DEFAULT_SCALE
1111

12-
class ImageOptions(options: ReadableMap) {
13-
var src: ReadableMap?
12+
class ImageOptions(val options: ReadableMap) {
13+
var src: ReadableMap? = options.getMap("src")
1414

1515
var uri: String?
1616

@@ -20,7 +20,6 @@ class ImageOptions(options: ReadableMap) {
2020
private var alpha: Int
2121

2222
init {
23-
src = options.getMap("src")
2423
if (src == null) {
2524
throw MarkerError(ErrorCode.PARAMS_REQUIRED, "image is required")
2625
}

0 commit comments

Comments
 (0)