Bodmer / TJpg_Decoder

Jpeg decoder library based on Tiny JPEG Decompressor
Other
227 stars 43 forks source link

Pointers for writing text over a JPG #5

Closed robotzero1 closed 4 years ago

robotzero1 commented 4 years ago

Hi, I'm not sure if I'm barking up the right tree but I've looked at your library and it looks like it could do some of what I need.

I have a Telegram bot running on an ESP32-CAM that returns a photo on request. I want to code something similar where a static photo (not from the camera) is returned with some text overlaid that the user sends.

I can work out how to do this with the frame buffer from the camera (the text overlay code is in the Espressif CameraWebServer example) but I want to use a JPG I have (maybe as a C array as in your examples).

Do you have some pointers on how I could proceed?

This is the code I use to send the framebuffer as a JPG.

bool isMoreDataAvailable() {
  return (fb_length - currentByte);
}

uint8_t photoNextByte() {
  currentByte++;
  return (fb_buffer[currentByte - 1]);
}

void take_send_photo(String chat_id, String message)
{
  camera_fb_t * fb = NULL;
  fb = esp_camera_fb_get();
  currentByte = 0;
  fb_length = fb->len;
  fb_buffer = fb->buf;
  bot.sendPhotoByBinary(chat_id, "image/jpeg", fb->len, isMoreDataAvailable, photoNextByte);
  esp_camera_fb_return(fb);
  fb_length = NULL;
  fb_buffer = NULL;  
}
Bodmer commented 4 years ago

To write text over a jpeg you will need to decode the image first, then encode it again afterwards if you wish to retain the compression provided by jpeg. The problem is that you will need to buffer and store the decoded image in memory and hence you will only be able to do this for small images. To write text over the image in memory you will need a graphics library. This library only decodes the jpeg.

I think you need to look for another solution that is compatible with streaming data.