Skip to content

Commit

Permalink
Fix uncompressable files
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasss93 committed Oct 28, 2021
1 parent 1bc2220 commit ec05731
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app/Jobs/OptimizeStickerJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ public function handle(Nutgram $bot): void
$image->filter(WatermarkFilter::make($chatSettings));

//compress image
$quality = 100;
do {
$stream = $image->stream('png', $quality);
$quality--;
} while ($stream->getSize() > TelegramLimit::STICKER_MAX_SIZE);
$ext = 'png';
$stream = $image->stream('png');
if ($stream->getSize() > TelegramLimit::STICKER_MAX_SIZE) {
$quality = 100;
do {
$stream = $image->stream('webp', $quality);
$quality--;
} while ($stream->getSize() > TelegramLimit::STICKER_MAX_SIZE);
$ext = 'webp';
}

//send optimized image
$bot->sendDocument(InputFile::make($stream->detach(), Str::uuid().'.png'), [
$bot->sendDocument(InputFile::make($stream->detach(), Str::uuid().'.'.$ext), [
'caption' => message('donate.caption'),
'parse_mode' => ParseMode::HTML,
'chat_id' => $this->chatID,
Expand Down

0 comments on commit ec05731

Please sign in to comment.