diff --git a/README.adoc b/README.adoc index ace7939..c9594f3 100644 --- a/README.adoc +++ b/README.adoc @@ -19,8 +19,6 @@ Maybe once there will be a webpage or API, but not in near future. This feature has all steps to make a telegram sticker such as: -* Remove image background(it`s not perfect, so keep that in mind); -* Crop empty space; * Resize image to sticker size(at least one side should be exactly 512px); * Add top and bottom text(in case of adding top text 15% top padding will be added as well); @@ -36,6 +34,20 @@ Basically the result is something like this: After that you can use https://t.me/Stickers to add sticker to stickerpack or create a new one. +==== Create meme (/crt-meme) + +This feature adds text to an image: + +The result is something like this: + +[cols="a,a", role="center"] +|=== +| Source | Result + +| image::example-meme-before.jpeg[] +| image::example-meme-after.jpeg[] +|=== + ==== Swap face (/swp-face) This feature allows to put face from one image to another diff --git a/docs/img/example-meme-after.jpeg b/docs/img/example-meme-after.jpeg new file mode 100644 index 0000000..7ff1256 Binary files /dev/null and b/docs/img/example-meme-after.jpeg differ diff --git a/docs/img/example-meme-before.jpeg b/docs/img/example-meme-before.jpeg new file mode 100644 index 0000000..9b74f12 Binary files /dev/null and b/docs/img/example-meme-before.jpeg differ diff --git a/src/main/kotlin/com/kvsinyuk/stickergenerator/adapter/in/telegram/handlers/meme/MemeBottomTextHandler.kt b/src/main/kotlin/com/kvsinyuk/stickergenerator/adapter/in/telegram/handlers/meme/MemeBottomTextHandler.kt index aed75e1..63f2fc4 100644 --- a/src/main/kotlin/com/kvsinyuk/stickergenerator/adapter/in/telegram/handlers/meme/MemeBottomTextHandler.kt +++ b/src/main/kotlin/com/kvsinyuk/stickergenerator/adapter/in/telegram/handlers/meme/MemeBottomTextHandler.kt @@ -27,6 +27,6 @@ class MemeBottomTextHandler( override fun canApply(update: TelegramUpdateMessage) = update.takeIf { !it.message.isNullOrBlank() } - ?.let { findBotDataPort.findByChatId(it.chatId)?.isStickerDataWithTopText() == true } + ?.let { findBotDataPort.findByChatId(it.chatId)?.isMemeDataWithTopText() == true } ?: false } diff --git a/src/main/kotlin/com/kvsinyuk/stickergenerator/adapter/in/telegram/handlers/meme/MemeTopTextHandler.kt b/src/main/kotlin/com/kvsinyuk/stickergenerator/adapter/in/telegram/handlers/meme/MemeTopTextHandler.kt index 1b59c6c..db4265b 100644 --- a/src/main/kotlin/com/kvsinyuk/stickergenerator/adapter/in/telegram/handlers/meme/MemeTopTextHandler.kt +++ b/src/main/kotlin/com/kvsinyuk/stickergenerator/adapter/in/telegram/handlers/meme/MemeTopTextHandler.kt @@ -21,6 +21,6 @@ class MemeTopTextHandler( override fun canApply(update: TelegramUpdateMessage) = update.takeIf { !it.message.isNullOrBlank() } - ?.let { findBotDataPort.findByChatId(update.chatId)?.isStickerDataWithSourceFile() == true } + ?.let { findBotDataPort.findByChatId(update.chatId)?.isMemeDataWithSourceFile() == true } ?: false } diff --git a/src/main/kotlin/com/kvsinyuk/stickergenerator/applicaiton/port/in/telegram/AddImageUseCase.kt b/src/main/kotlin/com/kvsinyuk/stickergenerator/applicaiton/port/in/telegram/AddImageUseCase.kt index 8562ace..aa301e6 100644 --- a/src/main/kotlin/com/kvsinyuk/stickergenerator/applicaiton/port/in/telegram/AddImageUseCase.kt +++ b/src/main/kotlin/com/kvsinyuk/stickergenerator/applicaiton/port/in/telegram/AddImageUseCase.kt @@ -27,7 +27,7 @@ abstract class AddImageUseCase( data: BotData, image: Image, ): BotData { - return data.setImage(image) + return data.addImage(image) } data class AddImageCommand( @@ -59,6 +59,6 @@ class AddImageWithResizeUseCaseImpl( val resizedImage = resizeImageService.resizeBufferedImage(image.image.toBufferedImage()) .let { image.copy(image = it.toByteArray()) } - return data.setImage(resizedImage) + return data.addImage(resizedImage) } } diff --git a/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/BotData.kt b/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/BotData.kt index 31039cd..13ac0de 100644 --- a/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/BotData.kt +++ b/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/BotData.kt @@ -4,6 +4,7 @@ import com.kvsinyuk.stickergenerator.domain.command.CommandData import com.kvsinyuk.stickergenerator.domain.command.FaceSwapData import com.kvsinyuk.stickergenerator.domain.command.FaceSwapStatus import com.kvsinyuk.stickergenerator.domain.command.MemeData +import com.kvsinyuk.stickergenerator.domain.command.MemeStatus import com.kvsinyuk.stickergenerator.domain.command.StickerData import com.kvsinyuk.stickergenerator.domain.command.StickerStatus import org.springframework.data.annotation.Id @@ -44,14 +45,11 @@ data class BotData( return this } - fun addImage( - file: ByteArray, - fileName: String, - ): BotData { + fun addImage(image: Image): BotData { when (commandData) { - is MemeData -> commandData.addImage(file, fileName) - is StickerData -> commandData.addImage(file, fileName) - is FaceSwapData -> commandData.addImage(file, fileName) + is MemeData -> commandData.addImage(image) + is StickerData -> commandData.addImage(image) + is FaceSwapData -> commandData.addImage(image) else -> {} } return this @@ -59,6 +57,8 @@ data class BotData( fun getAsStickerData() = commandData as StickerData + fun getAsMemeData() = commandData as MemeData + fun getAsFaceSwapData() = commandData as FaceSwapData fun isRemoveBackgroundData() = commandData.isRemoveBackgroundData() @@ -73,6 +73,10 @@ data class BotData( fun isStickerDataWithSourceFile() = isStickerData() && getAsStickerData().status == StickerStatus.SOURCE_FILE_ADDED + fun isMemeDataWithSourceFile() = isMemeData() && getAsMemeData().status == MemeStatus.SOURCE_FILE_ADDED + + fun isMemeDataWithTopText() = isMemeData() && getAsMemeData().status == MemeStatus.TOP_TEXT_ADDED + fun isFaceSwapDataWithSourceFile() = isFaceSwapData() && getAsFaceSwapData().status == FaceSwapStatus.SOURCE_FILE_ADDED fun isFaceSwapDataInit() = isFaceSwapData() && getAsFaceSwapData().status == FaceSwapStatus.INIT diff --git a/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/command/FaceSwapData.kt b/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/command/FaceSwapData.kt index fc1c048..b685074 100644 --- a/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/command/FaceSwapData.kt +++ b/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/command/FaceSwapData.kt @@ -14,21 +14,18 @@ data class FaceSwapData( override fun getSourceImage() = faceImage - fun addImage( - file: ByteArray, - fileName: String, - ) { + fun addImage(image: Image) { when (status) { FaceSwapStatus.INIT -> { - faceImage = Image(file, fileName) + faceImage = image status = FaceSwapStatus.SOURCE_FILE_ADDED } FaceSwapStatus.SOURCE_FILE_ADDED -> { - targetImage = Image(file, fileName) + targetImage = image status = FaceSwapStatus.TARGET_FILE_ADDED } - else -> null + else -> {} } } } diff --git a/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/command/MemeData.kt b/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/command/MemeData.kt index 69866c0..4e4927d 100644 --- a/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/command/MemeData.kt +++ b/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/command/MemeData.kt @@ -27,12 +27,9 @@ data class MemeData( } } - fun addImage( - file: ByteArray, - fileName: String, - ) { + fun addImage(image: Image) { status = MemeStatus.SOURCE_FILE_ADDED - image = Image(file, fileName) + this.image = image } } diff --git a/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/command/StickerData.kt b/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/command/StickerData.kt index 1e15781..421be2c 100644 --- a/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/command/StickerData.kt +++ b/src/main/kotlin/com/kvsinyuk/stickergenerator/domain/command/StickerData.kt @@ -27,12 +27,9 @@ data class StickerData( } } - fun addImage( - file: ByteArray, - fileName: String, - ) { + fun addImage(image: Image) { status = StickerStatus.SOURCE_FILE_ADDED - image = Image(file, fileName) + this.image = image } }