Skip to content

Commit

Permalink
stickers: remove the libwebp external dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
akshettrj committed Jun 30, 2024
1 parent 5a3cd66 commit cdbb2ee
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 176 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ from Telegram.

<a href="https://t.me/PropheCProjects">
<img src="https://img.shields.io/badge/Updates_Channel-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white"></img>
</a>&nbsp; &nbsp;
</a>&nbsp; &nbsp;
<a href="https://t.me/WaTgBridge">
<img src="https://img.shields.io/badge/Discussion_Group-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white"></img>
</a>&nbsp; &nbsp;
</a>&nbsp; &nbsp;
<a href="https://youtu.be/xc75XLoTmA4">
<img src="https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white"</img>
</a>
Expand Down Expand Up @@ -47,7 +47,7 @@ PRs are welcome :)

- Make a supergroup (enable message history for new members) with topics enabled
- Add your bot in the group, make it an admin with permissions to `Manage topics`
- Install `git`, `gcc` and `golang`, `ffmpeg` , `imagemagick` (optional), `libwebp` (latest version) on your system
- Install `git`, `gcc` and `golang`, `ffmpeg` , `imagemagick` (optional), on your system
- Clone this repository anywhere and navigate to the cloned directory
- Run `go build`
- Copy `sample_config.yaml` to `config.yaml` and fill the values, there are comments to help you.
Expand Down
9 changes: 3 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
module watgbridge

go 1.21

toolchain go1.22.2
go 1.22.3

require (
github.com/Benau/tgsconverter v0.0.0-20210809170556-99f4a4f6337f
github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.27
github.com/emersion/go-vcard v0.0.0-20230815062825-8fda7d206ec9
github.com/forPelevin/gomoji v1.2.0
github.com/go-co-op/gocron v1.37.0
github.com/jackc/pgx/v5 v5.5.5
github.com/kolesa-team/go-webp v1.0.4
github.com/lithammer/fuzzysearch v1.1.8
github.com/mattn/go-sqlite3 v1.14.22
github.com/mdp/qrterminal/v3 v3.2.0
github.com/watgbridge/tgsconverter v0.0.0-20240630070853-83de423ff0ec
github.com/watgbridge/webp v0.0.0-20240630070243-84d3a70502bb
go.mau.fi/whatsmeow v0.0.0-20240520180327-81f8f07f1dfb
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
Expand Down Expand Up @@ -44,7 +42,6 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rs/zerolog v1.32.0 // indirect
github.com/sizeofint/webpanimation v0.0.0-20210809145948-1d2b32119882 // indirect
go.mau.fi/libsignal v0.1.0 // indirect
go.mau.fi/util v0.4.2 // indirect
go.uber.org/atomic v1.11.0 // indirect
Expand Down
139 changes: 7 additions & 132 deletions go.sum

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ schema = 3
[mod."github.com/Benau/go_rlottie"]
version = "v0.0.0-20210807002906-98c1b2421989"
hash = "sha256-oIe5oARFioEFTv/tR8V0PJGvsW1qB0/ZFo7E/UPhJX4="
[mod."github.com/Benau/tgsconverter"]
version = "v0.0.0-20210809170556-99f4a4f6337f"
hash = "sha256-RTGCRJWX5JOWuNJ76uMyy3PzEgRlUDvNJ2mjckunp5o="
[mod."github.com/PaulSonOfLars/gotgbot/v2"]
version = "v2.0.0-rc.27"
hash = "sha256-SvKMqWCkKPKjJEH3QpXYWAfQa+ruJK7+KfoEStpWbt8="
Expand Down Expand Up @@ -55,9 +52,6 @@ schema = 3
[mod."github.com/kettek/apng"]
version = "v0.0.0-20220823221153-ff692776a607"
hash = "sha256-VuxcQDPJsmSpueFu9ECqG/EIr29eDALA1iRpl2pquzI="
[mod."github.com/kolesa-team/go-webp"]
version = "v1.0.4"
hash = "sha256-9yXYck2+V3UiYoceKEVCwfX4RUbo2xmD6hsjDPwtQnY="
[mod."github.com/lithammer/fuzzysearch"]
version = "v1.1.8"
hash = "sha256-aMMRcrlUc9CBiiNkcnWWn4hfNMNyVhrAt67kvP4D4Do="
Expand All @@ -82,9 +76,12 @@ schema = 3
[mod."github.com/rs/zerolog"]
version = "v1.32.0"
hash = "sha256-9dZjtsES+wLp1cFiSVMuEUbdeXVFcgT0dgg5ACZkILk="
[mod."github.com/sizeofint/webpanimation"]
version = "v0.0.0-20210809145948-1d2b32119882"
hash = "sha256-WlTBMUd+SLAh1TWuVHIWm/wy9cblds3f+yZYC3jJs/w="
[mod."github.com/watgbridge/tgsconverter"]
version = "v0.0.0-20240630070853-83de423ff0ec"
hash = "sha256-d8FdFV4/VlXsie+6D50qJS8OtU+W+ECRTTbkzLRpsgA="
[mod."github.com/watgbridge/webp"]
version = "v0.0.0-20240630070243-84d3a70502bb"
hash = "sha256-DUFTpV/qVqjHavAdv+5HuOn7lDq4Fu2EU4iZQNjwy14="
[mod."go.mau.fi/libsignal"]
version = "v0.1.0"
hash = "sha256-hSZQkw/0eV5Y0pj1N+idYuKb/jtiw/qTfaOGdYCXmn0="
Expand Down
5 changes: 1 addition & 4 deletions nix/pkgs/watgbridge-dev.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
{ lib
, buildGoApplication
, libwebp
}:

buildGoApplication rec {
pname = "watgbridge-dev";
pname = "watgbridge";
version = "1.8.2";

pwd = ../../.;
src = ../../.;

buildInputs = [ libwebp ];

ldflags = [ "-s" "-w" ];

meta = with lib; rec {
Expand Down
2 changes: 1 addition & 1 deletion state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"gorm.io/gorm"
)

const WATGBRIDGE_VERSION = "1.8.2"
const WATGBRIDGE_VERSION = "1.9.0"

type state struct {
Config *Config
Expand Down
30 changes: 9 additions & 21 deletions utils/stickers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import (

"watgbridge/state"

"github.com/Benau/tgsconverter/libtgsconverter"
"github.com/kolesa-team/go-webp/decoder"
"github.com/kolesa-team/go-webp/encoder"
"github.com/kolesa-team/go-webp/webp"
"github.com/watgbridge/tgsconverter/libtgsconverter"
"github.com/watgbridge/webp"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -96,14 +94,9 @@ func WebmConvertToWebp(webmStickerData []byte, scale, pad string, updateId int64
}

func WebpImagePad(inputData []byte, wPad, hPad int, updateId int64) ([]byte, error) {
webpDecoder, err := decoder.NewDecoder(bytes.NewBuffer(inputData), &decoder.Options{NoFancyUpsampling: true})
inputImage, err := webp.DecodeRGB(inputData)
if err != nil {
return nil, fmt.Errorf("failed to create a webp decoder: %s", err)
}

inputImage, err := webpDecoder.Decode()
if err != nil {
return nil, fmt.Errorf("failed to decode webp image: %s", err)
return nil, fmt.Errorf("failed to decode web image: %w", err)
}

var (
Expand All @@ -112,26 +105,21 @@ func WebpImagePad(inputData []byte, wPad, hPad int, updateId int64) ([]byte, err
)

outputWidth := inputImage.Bounds().Dx() + wPad
outputHeight := inputImage.Bounds().Dy() + hPad
outputHeight := inputImage.Bounds().Dx() + hPad

outputImage := image.NewRGBA(image.Rect(0, 0, outputWidth, outputHeight))
draw.Draw(outputImage, image.Rect(wOffset, hOffset, outputWidth-wOffset, outputHeight-hOffset), inputImage, image.Point{}, draw.Src)

encoderOptions, err := encoder.NewLossyEncoderOptions(encoder.PresetDefault, 100)
outputBytes, err := webp.EncodeRGB(outputImage, 100)
if err != nil {
return nil, fmt.Errorf("failed to initialize encoder options: %s", err)
}

var outputBuffer bytes.Buffer
if err = webp.Encode(&outputBuffer, outputImage, encoderOptions); err != nil {
return nil, fmt.Errorf("failed to encode into webp: %s", err)
return nil, fmt.Errorf("failed to encode padded data into Webp: %w", err)
}

if outputData, err := WebpWriteExifData(outputBuffer.Bytes(), updateId); err == nil {
if outputData, err := WebpWriteExifData(outputBytes, updateId); err == nil {
return outputData, nil
}

return outputBuffer.Bytes(), nil
return outputBytes, nil
}

func AnimatedWebpConvertToGif(inputData []byte, updateId string) ([]byte, error) {
Expand Down

0 comments on commit cdbb2ee

Please sign in to comment.