Skip to content

Commit

Permalink
Added None, Fill, Fit, FitWidth, FitHeight, Crop scale types for Stac…
Browse files Browse the repository at this point in the history
…k Images tool
  • Loading branch information
T8RIN committed Jan 21, 2025
1 parent 85ce97c commit 857e765
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,26 +290,28 @@ internal class AndroidImageScaler @Inject constructor(
imageScaleMode = imageScaleMode
)

val blurredBitmap = imageTransformer.transform(
image = drawImage.let { bitmap ->
val xScale: Float = targetWidth.toFloat() / originalWidth
val yScale: Float = targetHeight.toFloat() / originalHeight
val scale = xScale.coerceAtLeast(yScale)
createScaledBitmap(
image = bitmap,
width = (scale * originalWidth).toInt(),
height = (scale * originalHeight).toInt(),
imageScaleMode = imageScaleMode
)
},
transformations = listOf(
filterProvider.filterToTransformation(
createFilter<Float, Filter.NativeStackBlur>(
blurRadius.toFloat() / 1000 * max(targetWidth, targetHeight)
val blurredBitmap = if (canvasColor == null) {
imageTransformer.transform(
image = drawImage.let { bitmap ->
val xScale: Float = targetWidth.toFloat() / originalWidth
val yScale: Float = targetHeight.toFloat() / originalHeight
val scale = xScale.coerceAtLeast(yScale)
createScaledBitmap(
image = bitmap,
width = (scale * originalWidth).toInt(),
height = (scale * originalHeight).toInt(),
imageScaleMode = imageScaleMode
)
},
transformations = listOf(
filterProvider.filterToTransformation(
createFilter<Float, Filter.NativeStackBlur>(
blurRadius.toFloat() / 1000 * max(targetWidth, targetHeight)
)
)
)
)
)
} else null

Bitmap.createBitmap(
targetWidth,
Expand Down
2 changes: 2 additions & 0 deletions core/resources/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1564,4 +1564,6 @@
<string name="edit_exif_screen_sub">Change metadata of single image without recompression</string>
<string name="edit_exif_tag">Tap to edit available tags</string>
<string name="change_sticker">Change Sticker</string>
<string name="fit_width">Fit Width</string>
<string name="fit_height">Fit Height</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,23 @@ internal class AndroidImageStacker @Inject constructor(
)?.let { bitmap ->
bitmap.setHasAlpha(true)

when (stackImage.scale) {
StackImage.Scale.None -> bitmap
StackImage.Scale.Fill -> imageScaler.scaleImage(
image = bitmap,
width = resultSize.width,
height = resultSize.height
)
val resizeType = when (stackImage.scale) {
StackImage.Scale.None -> null
StackImage.Scale.Fill -> ResizeType.Explicit
StackImage.Scale.Fit -> ResizeType.Flexible(ResizeAnchor.Min)
StackImage.Scale.FitWidth -> ResizeType.Flexible(ResizeAnchor.Width)
StackImage.Scale.FitHeight -> ResizeType.Flexible(ResizeAnchor.Height)
StackImage.Scale.Crop -> ResizeType.CenterCrop(0x00000000)
}

StackImage.Scale.Fit -> imageScaler.scaleImage(
resizeType?.let {
imageScaler.scaleImage(
image = bitmap,
width = resultSize.width,
height = resultSize.height,
resizeType = ResizeType.Flexible(ResizeAnchor.Min)
resizeType = resizeType
)
}
} ?: bitmap
}
paint.alpha = (stackImage.alpha * 255).toInt()
paint.xfermode = PorterDuffXfermode(stackImage.blendingMode.toPorterDuffMode())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data class StackImage(
val scale: Scale
) {
enum class Scale {
None, Fill, Fit
None, Fill, Fit, FitWidth, FitHeight, Crop
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ fun StackImageItem(
StackImage.Scale.None -> stringResource(R.string.none)
StackImage.Scale.Fill -> stringResource(R.string.fill)
StackImage.Scale.Fit -> stringResource(R.string.fit)
StackImage.Scale.FitWidth -> stringResource(R.string.fit_width)
StackImage.Scale.FitHeight -> stringResource(R.string.fit_height)
StackImage.Scale.Crop -> stringResource(R.string.crop)
}
},
color = Color.Unspecified,
Expand Down

0 comments on commit 857e765

Please sign in to comment.