Skip to content

Commit 1c62250

Browse files
authored
fix: fix #179 same watermark image is behaving differently on android and ios when use given position enum (#187)
* chore: update gradle-wrapper.properties use gradle 8.3 * fix: #179 Same watermark image is behaving differently on ANDROID and IOS when use given position enum fix #179 Same watermark image is behaving differently on ANDROID and IOS when use given position enum * chore: release 1.2.1
1 parent 53ac1f1 commit 1c62250

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11

22

3-
# [1.2.0](https://github.com/JimmyDaddy/react-native-image-marker/compare/v1.1.8...v1.2.0) (2023-12-21)
3+
## [1.2.1](https://github.com/JimmyDaddy/react-native-image-marker/compare/v1.2.0...v1.2.1) (2023-12-28)
4+
5+
### Bug Fixes
6+
7+
* [#179](https://github.com/JimmyDaddy/react-native-image-marker/issues/179) Same watermark image is behaving differently on ANDROID and IOS when use given position enum ([39107f0](https://github.com/JimmyDaddy/react-native-image-marker/commit/39107f0977a400faf4dc7ed8f94e3877287d9d78))
8+
* parse hex color string crash on iOS ([#186](https://github.com/JimmyDaddy/react-native-image-marker/issues/186)) ([53ac1f1](https://github.com/JimmyDaddy/react-native-image-marker/commit/53ac1f14461e3007a2e028d0c401a1eed3ddd962))
9+
10+
## [1.2.0](https://github.com/JimmyDaddy/react-native-image-marker/compare/v1.1.8...v1.2.0) (2023-12-21)
411

512

613
### Bug Fixes
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

ios/RCTImageMarker/ImageMarker.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public final class ImageMarker: NSObject, RCTBridgeModule {
273273

274274
func markImage(with image: UIImage, waterImages: [UIImage], options: MarkImageOptions) -> UIImage? {
275275

276-
var bg = image;
276+
let bg = image;
277277
let w = bg.size.width
278278
let h = bg.size.height
279279
UIGraphicsBeginImageContextWithOptions(bg.size, false, options.backgroundImage.scale)
@@ -323,39 +323,43 @@ public final class ImageMarker: NSObject, RCTBridgeModule {
323323
case .topLeft:
324324
rect = CGRect(origin: CGPoint(x: 20, y: 20), size: size)
325325
case .topCenter:
326-
rect = CGRect(origin: CGPoint(x: (w - size.width) / 2, y: 20), size: size)
326+
rect = CGRect(origin: CGPoint(x: (w - ww) / 2, y: 20), size: size)
327327
case .topRight:
328-
rect = CGRect(origin: CGPoint(x: w - size.width - 20, y: 20), size: size)
328+
rect = CGRect(origin: CGPoint(x: w - ww - 20, y: 20), size: size)
329329
case .bottomLeft:
330-
rect = CGRect(origin: CGPoint(x: 20, y: h - size.height - 20), size: size)
330+
rect = CGRect(origin: CGPoint(x: 20, y: h - wh - 20), size: size)
331331
case .bottomCenter:
332-
rect = CGRect(origin: CGPoint(x: (w - size.width) / 2, y: h - size.height - 20), size: size)
332+
rect = CGRect(origin: CGPoint(x: (w - ww) / 2, y: h - wh - 20), size: size)
333333
case .bottomRight:
334-
rect = CGRect(origin: CGPoint(x: w - size.width - 20, y: h - size.height - 20), size: size)
334+
rect = CGRect(origin: CGPoint(x: w - ww - 20, y: h - wh - 20), size: size)
335335
case .center:
336-
rect = CGRect(origin: CGPoint(x: (w - size.width) / 2, y: (h - size.height) / 2), size: size)
336+
rect = CGRect(origin: CGPoint(x: (w - ww) / 2, y: (h - wh) / 2), size: size)
337337
default:
338338
rect = CGRect(origin: CGPoint(x: 20, y: 20), size: size)
339339
}
340340
} else {
341-
rect = CGRect(x: Utils.parseSpreadValue(v: watermarkOptions.X, relativeTo: w) ?? 20, y: Utils.parseSpreadValue(v: watermarkOptions.Y, relativeTo: h) ?? 20, width: CGFloat(ww), height: CGFloat(wh))
341+
rect = CGRect(x: Utils.parseSpreadValue(v: watermarkOptions.X, relativeTo: w) ?? 20, y: Utils.parseSpreadValue(v: watermarkOptions.Y, relativeTo: h) ?? 20, width: diagonal, height: diagonal)
342342
}
343343

344344
UIGraphicsBeginImageContextWithOptions(CGSize(width: diagonal, height: diagonal), false, 1)
345345
let markerContext = UIGraphicsGetCurrentContext()
346+
markerContext?.setFillColor(UIColor.red.cgColor)
347+
markerContext?.fill(rect)
346348
markerContext?.saveGState()
347-
349+
348350
if watermarkOptions.imageOption.alpha != 1.0 {
349351
markerContext?.beginTransparencyLayer(auxiliaryInfo: nil)
350352
markerContext?.setAlpha(watermarkOptions.imageOption.alpha)
351353
markerContext?.setBlendMode(.multiply)
352354
let markerImage = markerImg.rotatedImageWithTransform(watermarkOptions.imageOption.rotate)
353-
markerContext?.draw(markerImage.cgImage!, in: CGRect(origin: .zero, size: CGSize(width: diagonal, height: diagonal)))
355+
let originPoint = CGPoint(x: 0, y: rect.height - markerImage.size.height)
356+
markerContext?.draw(markerImage.cgImage!, in: CGRect(origin: originPoint, size: CGSize(width: markerImage.size.width, height: markerImage.size.height)))
354357
markerContext?.endTransparencyLayer()
355358

356359
} else {
357360
let markerImage = markerImg.rotatedImageWithTransform(watermarkOptions.imageOption.rotate)
358-
markerContext?.draw(markerImage.cgImage!, in: CGRect(origin: .zero, size: CGSize(width: diagonal, height: diagonal)))
361+
let originPoint = CGPoint(x: 0, y: rect.height - markerImage.size.height)
362+
markerContext?.draw(markerImage.cgImage!, in: CGRect(origin: originPoint, size: CGSize(width: markerImage.size.width, height: markerImage.size.height)))
359363
}
360364
markerContext?.restoreGState()
361365

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-image-marker",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Add text or icon watermark to your images",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

0 commit comments

Comments
 (0)