0

I have an image of size (200 by 200). The image data is stored as <class 'bytes'> as below. Is there a way to pad the image to size (1,080 by 1,920)? This is not resize but pad the image to another size.

image_data = '\xc0q\xc7\x1c\x07\x1cq\xc0q\xc7\x1c\x07\x1cq\xc0\xff\xd9......'
sirimiri
  • 509
  • 2
  • 6
  • 18
  • Your question is unclear: What does `image_data` bytes represent? Is it a 200x200 Grayscale image (1 byte per pixel) or 200x200 RGB (3 bytes per pixel) image or something else? What do you mean by "pad the image"? Placing the image at the center of 1920x1080 black image? Some other way of padding? – Rotem Apr 12 '22 at 20:00

1 Answers1

0

Have you tried looking for the answer already?

There are a lot of answers given to this question already, like this one: (Add padding to images to get them into the same shape)

(https://www.geeksforgeeks.org/add-padding-to-the-image-with-python-pillow/)

It would also help to see what you've already tried and what failed exactly.

sidereal
  • 36
  • 6
  • yes i have but they are jpg format, but the data i have here is bytes – sirimiri Apr 12 '22 at 10:24
  • Well that doesn't matter; Images are made of a grid of pixels aka “picture elements”. A pixel contains 8 bits (1 byte) if it is in BW (black and white). For colored images it uses a certain color scheme called RGB (Red, Green, Blue) represented as 1 byte each or 24 bits (3 bytes) per pixel. This is also referred to as the bit depth of an image. [source](https://medium.com/hd-pro/the-relationship-of-image-resolution-to-image-size-1f6a28ea30bb). You're still working with pixels, please take a look at the links I provided :) – sidereal Apr 12 '22 at 10:30