python-imaging-library

convert pillow Image object to JpegImageFile object

我是研究僧i 提交于 2020-07-20 20:24:11
问题 I cropped an jpeg image, but the cropped image type is <class 'PIL.Image.Image'> how can i convert it to <class 'PIL.JpegImagePlugin.JpegImageFile'> ? thank you! import requests from PIL import Image from io import BytesIO img = Image.open(BytesIO(requests.get("https://mamahelpers.co/assets/images/faq/32B.JPG").content)) img2 = img.crop((1,20,50,80)) print(type(img)) # <class 'PIL.JpegImagePlugin.JpegImageFile'> print(type(img2)) # <class 'PIL.Image.Image'> 回答1: If you do not want a pyhsical

convert pillow Image object to JpegImageFile object

纵然是瞬间 提交于 2020-07-20 20:24:11
问题 I cropped an jpeg image, but the cropped image type is <class 'PIL.Image.Image'> how can i convert it to <class 'PIL.JpegImagePlugin.JpegImageFile'> ? thank you! import requests from PIL import Image from io import BytesIO img = Image.open(BytesIO(requests.get("https://mamahelpers.co/assets/images/faq/32B.JPG").content)) img2 = img.crop((1,20,50,80)) print(type(img)) # <class 'PIL.JpegImagePlugin.JpegImageFile'> print(type(img2)) # <class 'PIL.Image.Image'> 回答1: If you do not want a pyhsical

convert pillow Image object to JpegImageFile object

一笑奈何 提交于 2020-07-20 20:23:24
问题 I cropped an jpeg image, but the cropped image type is <class 'PIL.Image.Image'> how can i convert it to <class 'PIL.JpegImagePlugin.JpegImageFile'> ? thank you! import requests from PIL import Image from io import BytesIO img = Image.open(BytesIO(requests.get("https://mamahelpers.co/assets/images/faq/32B.JPG").content)) img2 = img.crop((1,20,50,80)) print(type(img)) # <class 'PIL.JpegImagePlugin.JpegImageFile'> print(type(img2)) # <class 'PIL.Image.Image'> 回答1: If you do not want a pyhsical

TypeError: unsupported operand type(s) for /: 'Image' and 'int'

走远了吗. 提交于 2020-07-08 19:22:30
问题 I wanted to convert the PIL Image object into a numpy array. I tried using the following codes it showing an error TypeError Traceback (most recent call last) <ipython-input-133-0898103f22f0> in <module>() 1 image_path = 'test/28/image_05230.jpg' ----> 2 image = process_image(image_path) 3 imshow(image) <ipython-input-129-e036faebfd31> in process_image(image_path) 24 # normalize 25 print(type(image)) ---> 26 image_arr = np.array(image) / 255 27 mean = np.array([0.485, 0.456, 0.406]) 28 std_dv

Using python's pillow library: how to draw text without creating draw object of an image

不想你离开。 提交于 2020-07-07 07:32:30
问题 the code bellow shows how to write text on image with creating a draw object from PIL import Image, ImageFont, ImageDraw image = Image.new(mode = "RGBA" , size= (500, 508) ) draw = ImageDraw.Draw(image) font = ImageFont.load("arial.pil") draw.text((10, 10), "hello", font=font) what i'm asking for is how to return the text as a pillow object so i can just paste it on another images without having to create image object and draw object then writing text on them, i just want the raw text as a

Using python's pillow library: how to draw text without creating draw object of an image

自古美人都是妖i 提交于 2020-07-07 07:31:23
问题 the code bellow shows how to write text on image with creating a draw object from PIL import Image, ImageFont, ImageDraw image = Image.new(mode = "RGBA" , size= (500, 508) ) draw = ImageDraw.Draw(image) font = ImageFont.load("arial.pil") draw.text((10, 10), "hello", font=font) what i'm asking for is how to return the text as a pillow object so i can just paste it on another images without having to create image object and draw object then writing text on them, i just want the raw text as a

Using python's pillow library: how to draw text without creating draw object of an image

社会主义新天地 提交于 2020-07-07 07:31:10
问题 the code bellow shows how to write text on image with creating a draw object from PIL import Image, ImageFont, ImageDraw image = Image.new(mode = "RGBA" , size= (500, 508) ) draw = ImageDraw.Draw(image) font = ImageFont.load("arial.pil") draw.text((10, 10), "hello", font=font) what i'm asking for is how to return the text as a pillow object so i can just paste it on another images without having to create image object and draw object then writing text on them, i just want the raw text as a

OpenCV - How to draw a line inside contour?

痞子三分冷 提交于 2020-07-07 06:53:39
问题 I'm working on a DIY 3d Scanner project. I'll use a pretty common algorithm for it. See here: https://lesagegp.wordpress.com/2013/12/04/laser-scanning-explained/ I've totally understood the algorithm and wrote a code for it. All I got to do now is processing the images. I've captured couple images for testing. Here is one of them: And I've managed to find contours of the laser with a very simple code: image = cv2.imread("frame/1.png") image = cv2.flip(image, 1) hsv_frame = cv2.cvtColor(image,

OpenCV - How to draw a line inside contour?

三世轮回 提交于 2020-07-07 06:53:08
问题 I'm working on a DIY 3d Scanner project. I'll use a pretty common algorithm for it. See here: https://lesagegp.wordpress.com/2013/12/04/laser-scanning-explained/ I've totally understood the algorithm and wrote a code for it. All I got to do now is processing the images. I've captured couple images for testing. Here is one of them: And I've managed to find contours of the laser with a very simple code: image = cv2.imread("frame/1.png") image = cv2.flip(image, 1) hsv_frame = cv2.cvtColor(image,

How to change the dpi or density when saving images using PIL

╄→гoц情女王★ 提交于 2020-07-06 04:43:22
问题 I'm trying to compress a jpg file using PIL (to be more specific, Pillow) I know images can be compressed by doing this: from PIL import Image im = Image.open(img_path) im = im.resize(new_size, Image.ANTIALIAS) im.save(output_path, optimize=True, quality=50) But I want to go further by tweaking more params, like this: im.save(output_path, optimize=True, quality=50, jfif_unit=1, dpi=(72,72), jfif_density=(72,72)) Unfortunately, it does not change dpi or density at all. How am I suppose to