Move UriGlideRenderer to lib:image-editor.

This commit is contained in:
Alex Hart
2026-01-29 12:37:21 -04:00
committed by Greyson Parrelli
parent 7bd3482367
commit 7823d4f49f
9 changed files with 103 additions and 48 deletions

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2026 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.signal.core.util
import android.graphics.Bitmap
import androidx.core.graphics.scale
/**
* Creates a scaled bitmap with the given maximum dimensions while maintaining the original aspect ratio.
*/
fun Bitmap.scaleWithAspectRatio(maxWidth: Int, maxHeight: Int): Bitmap {
if (getWidth() <= maxWidth && getHeight() <= maxHeight) {
return this
}
if (maxWidth <= 0 || maxHeight <= 0) {
return this
}
var newWidth = maxWidth
var newHeight = maxHeight
val widthRatio: Float = getWidth() / maxWidth.toFloat()
val heightRatio: Float = getHeight() / maxHeight.toFloat()
if (widthRatio > heightRatio) {
newHeight = (getHeight() / widthRatio).toInt()
} else {
newWidth = (getWidth() / heightRatio).toInt()
}
return scale(newWidth, newHeight)
}