python-imaging-library

How to write CUSTOM metadata into JPEG with Python?

孤者浪人 提交于 2020-03-19 05:08:26
问题 How to write CUSTOM metadata into JPEG with Python? I tried import piexif exif_dict = { 'uwi': myvalue1, 'activity_type': myvalue2, 'prediction': myvalue3, 'url_current': myvalue4, 'url_previous': mavalue5 } exif_bytes = piexif.dump(exif_dict) with open(filename, "w") as fp: test_image.save(fp, "JPEG", exif=exif_bytes) but see nothing in images with XnView . What am I doing wrong? P.S. I don't need to write camera model, exposure and other stuff. I want to write my own custom metadata. 回答1:

Is there a way to outline text with a dark line in PIL?

眉间皱痕 提交于 2020-03-18 03:43:58
问题 I'm using python/PIL to write text on a set of PNG images. I was able to get the font I wanted, but I'd like to now outline the text in black. This is what I have: as you can see, if the background is white it is difficult to read. This is the goal: Is there a way to accomplish this with PIL? If not, I am open to hearing other suggestions, but no promises because I've already begun a large project in python using PIL. The section of code that deals with drawing on the images: for i in range(0

Is there a way to outline text with a dark line in PIL?

只谈情不闲聊 提交于 2020-03-18 03:43:14
问题 I'm using python/PIL to write text on a set of PNG images. I was able to get the font I wanted, but I'd like to now outline the text in black. This is what I have: as you can see, if the background is white it is difficult to read. This is the goal: Is there a way to accomplish this with PIL? If not, I am open to hearing other suggestions, but no promises because I've already begun a large project in python using PIL. The section of code that deals with drawing on the images: for i in range(0

PIL TypeError: Cannot handle this data type

孤者浪人 提交于 2020-03-17 08:47:04
问题 I have an image stored in a numpy array that I want to convert to PIL.Image in order to perform an interpolation only available with PIL. When trying to convert it through Image.fromarray() it raises the following error: TypeError: Cannot handle this data type I have read the answers here and here but they do not seem to help in my situation. What I'm trying to run: from PIL import Image x # a numpy array representing an image, shape: (256, 256, 3) Image.fromarray(x) 回答1: tl;dr Does x contain

PIL TypeError: Cannot handle this data type

送分小仙女□ 提交于 2020-03-17 08:46:09
问题 I have an image stored in a numpy array that I want to convert to PIL.Image in order to perform an interpolation only available with PIL. When trying to convert it through Image.fromarray() it raises the following error: TypeError: Cannot handle this data type I have read the answers here and here but they do not seem to help in my situation. What I'm trying to run: from PIL import Image x # a numpy array representing an image, shape: (256, 256, 3) Image.fromarray(x) 回答1: tl;dr Does x contain

getbbox method from python image library (PIL) not working

不想你离开。 提交于 2020-03-17 07:23:07
问题 I want to crop an image to its smaller size, by cutting the white areas on the borders. I tried the solution suggested in this forum Crop a PNG image to its minimum size but the getbbox() method of pil is returning a bounding box of the same size of the image, i.e., it seems that it doesn't recognize the blank areas around. I tried the following: >>>import Image >>>im=Image.open("myfile.png") >>>print im.format, im.size, im.mode >>>print im.getbbox() PNG (2400,1800) RGBA (0,0,2400,1800) I

getbbox method from python image library (PIL) not working

半世苍凉 提交于 2020-03-17 07:23:06
问题 I want to crop an image to its smaller size, by cutting the white areas on the borders. I tried the solution suggested in this forum Crop a PNG image to its minimum size but the getbbox() method of pil is returning a bounding box of the same size of the image, i.e., it seems that it doesn't recognize the blank areas around. I tried the following: >>>import Image >>>im=Image.open("myfile.png") >>>print im.format, im.size, im.mode >>>print im.getbbox() PNG (2400,1800) RGBA (0,0,2400,1800) I

Measuring width of text (Python/PIL)

…衆ロ難τιáo~ 提交于 2020-03-17 04:38:49
问题 I'm using the following two methods to calculate a sample string's rendered width for a set font-type and size: font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 14) sample = "Lorem ipsum dolor sit amet, partem periculis an duo, eum lorem paulo an, mazim feugiat lobortis sea ut. In est error eirmod vituperata, prima iudicabit rationibus mel et. Paulo accumsan ad sit, et modus assueverit eum. Quod homero adversarium vel ne, mel noster dolorum te, qui ea senserit

Measuring width of text (Python/PIL)

我的梦境 提交于 2020-03-17 04:38:04
问题 I'm using the following two methods to calculate a sample string's rendered width for a set font-type and size: font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 14) sample = "Lorem ipsum dolor sit amet, partem periculis an duo, eum lorem paulo an, mazim feugiat lobortis sea ut. In est error eirmod vituperata, prima iudicabit rationibus mel et. Paulo accumsan ad sit, et modus assueverit eum. Quod homero adversarium vel ne, mel noster dolorum te, qui ea senserit

Read image XMP data in Python

你离开我真会死。 提交于 2020-03-10 10:06:22
问题 Can I use PIL, like in this example? I only need to read the data, and I'm looking for the easiest simplest way to do it (I can't install pyexiv ) . edit: I don't want to believe that the only way to do this is with some library (python-xmp-toolkit, pyexiv2, ...) that needs Exempi and Boost. There must be another option! 回答1: Well, I was looking for something similar, then I came across the PHP equivalent question and I translated the anwer to Python: f = 'example.jpg' fd = open(f) d= fd.read