Skip to content

Commit

Permalink
chore: change screenshot image type from JPEG to WEBP
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Dec 4, 2024
1 parent 323a334 commit 866181c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

- chore: change screenshot image type from JPEG to WEBP ([#130](https://github.com/PostHog/posthog-android/pull/130))

## 3.9.3 - 2024-11-26

- no user facing changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,19 @@ private fun Bitmap.isValid(): Boolean {
height > 0
}

@PostHogInternal
@Suppress("DEPRECATION")
public fun Bitmap.webpBase64(quality: Int = 30): String? {
val format =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Bitmap.CompressFormat.WEBP_LOSSY
} else {
Bitmap.CompressFormat.WEBP
}

return base64(format, quality)
}

@PostHogInternal
@Suppress("DEPRECATION")
public fun Bitmap.base64(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ import com.posthog.PostHog
import com.posthog.PostHogIntegration
import com.posthog.android.PostHogAndroidConfig
import com.posthog.android.internal.MainHandler
import com.posthog.android.internal.base64
import com.posthog.android.internal.densityValue
import com.posthog.android.internal.displayMetrics
import com.posthog.android.internal.screenSize
import com.posthog.android.internal.webpBase64
import com.posthog.android.replay.PostHogMaskModifier.PostHogReplayMask
import com.posthog.android.replay.internal.NextDrawListener.Companion.onNextDraw
import com.posthog.android.replay.internal.ViewTreeSnapshotStatus
Expand Down Expand Up @@ -733,7 +733,7 @@ public class PostHogReplayIntegration(
canvas.drawRoundRect(RectF(it), 10f, 10f, paint)
}

base64 = bitmap.base64()
base64 = bitmap.webpBase64()
}
} catch (e: Throwable) {
config.logger.log("Session Replay PixelCopy failed: $e.")
Expand Down Expand Up @@ -1106,7 +1106,7 @@ public class PostHogReplayIntegration(
): String? {
val convertedBitmap = runDrawableConverter(this)
if (convertedBitmap != null) {
return convertedBitmap.base64()
return convertedBitmap.webpBase64()
}

var clonedDrawable = this
Expand All @@ -1117,7 +1117,7 @@ public class PostHogReplayIntegration(
when (clonedDrawable) {
is BitmapDrawable -> {
try {
return clonedDrawable.bitmap.base64()
return clonedDrawable.bitmap.webpBase64()
} catch (_: Throwable) {
// ignore
}
Expand All @@ -1138,7 +1138,7 @@ public class PostHogReplayIntegration(

try {
val bitmap = clonedDrawable.toBitmap(width, height)
val base64 = bitmap.base64()
val base64 = bitmap.webpBase64()
if (!bitmap.isRecycled) {
bitmap.recycle()
}
Expand Down

0 comments on commit 866181c

Please sign in to comment.