Skip to content

Commit

Permalink
Merge pull request #94 from kirillsinyuk/feature/93 #patch
Browse files Browse the repository at this point in the history
#93 add create-meme documentation
  • Loading branch information
kirillsinyuk authored Apr 26, 2024
2 parents bafccbb + 52b6d4a commit 1213785
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 30 deletions.
16 changes: 14 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
Binary file added docs/img/example-meme-after.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/example-meme-before.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class AddImageUseCase(
data: BotData,
image: Image,
): BotData {
return data.setImage(image)
return data.addImage(image)
}

data class AddImageCommand(
Expand Down Expand Up @@ -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)
}
}
18 changes: 11 additions & 7 deletions src/main/kotlin/com/kvsinyuk/stickergenerator/domain/BotData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,21 +45,20 @@ 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
}

fun getAsStickerData() = commandData as StickerData

fun getAsMemeData() = commandData as MemeData

fun getAsFaceSwapData() = commandData as FaceSwapData

fun isRemoveBackgroundData() = commandData.isRemoveBackgroundData()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 1213785

Please sign in to comment.