pillow

Saving an imshow-like image while preserving resolution

此生再无相见时 提交于 2020-01-29 03:25:31
问题 I have an (n, m) array that I've been visualizing with matplotlib.pyplot.imshow . I'd like to save this data in some type of raster graphics file (e.g. a png) so that: The colors are the ones shown with imshow Each element of the underlying array is exactly one pixel in the saved image -- meaning that if the underlying array is (n, m) elements, the image is NxM pixels. (I'm not interested in interpolation='nearest' in imshow .) There is nothing in the saved image except for the pixels

The niqqud are not aligned properly while drawing text in Hebrew using PIL (Python Imaging Library)

安稳与你 提交于 2020-01-23 02:26:25
问题 I'm using Pillow / PIL to draw hebrew letters with nikud. I noticed that the nikudim (plural for nikud) are not properly aligned and sometimes overlap other letters. Any suggested fix for this? I've tried a few fonts, and they all seem to have their own issues. Here's the code that I'm using. from bidi.algorithm import get_display from PIL import Image, ImageDraw, ImageFont fonts = [ ('Tammey FranckCLM', '/PATH/TO/FONT/TaameyFrankCLM-Medium.ttf'), ('Times New Roman', '/PATH/TO/FONT/Times New

Displaying uploaded images in the template - Django

不想你离开。 提交于 2020-01-22 17:01:30
问题 I am trying to display uploaded images to a template for my imaginary vegetable catalogue. I have a page to add a new vegetable and upload images. The main template is a list of vegetables which will later have thumbnails. Now, when viewing the detail page of the vegetable I want to display its images, but the template is only displaying the string 'VegetableImage Object' in place of an image, even with img tags. I am confused because the template has obviously found the images but they are

How to save images in specific file directories using Python PIL (Pillow) without getting a KeyError due to: save_handler = SAVE[format.upper()]

泄露秘密 提交于 2020-01-15 09:41:28
问题 I am trying to crop specific elements out of a larger image of the periodic table, then saving them in a specific file directory, this file directory is inside an additional folder, and this folder is in the same file directory as the program that I am trying to do this with. I have looked at another answered question on stack overflow that has similarities to my problem: How can I save an image with PIL? , however this user used 'numpy'. I have only previously learnt python basics in school

Is there a way to fallback for missing glyphs with PIL?

余生长醉 提交于 2020-01-15 03:43:10
问题 When rendering text using PIL (ImageFont, ImageDraw, etc.) if the font is missing a glyph for a particular character, it just skips that character. I don't see any mechanism in the docs for specifying a fallback font. Is there a tried-and-true recipe for using a fallback font for missing glyphs in PIL? 回答1: I couldn't figure out how to do this, but I did find a workaround. I used FontForge to fill in the missing glyphs in the main font, with backup glyphs from another font. As explained in

Python Export Excel Sheet Range as Image

社会主义新天地 提交于 2020-01-14 03:16:07
问题 So it seems there's something weird going on with PIL ImageGrab.grabclipboard() import win32com.client from PIL import ImageGrab o = win32com.client.Dispatch('Excel.Application') o.visible = False wb = o.Workbooks.Open(path) ws = wb.Worksheets['Global Dash'] ws.Range(ws.Cells(1,1),ws.Cells(66,16)).CopyPicture() img = ImageGrab.grabclipboard() imgFile = os.path.join(path_to_img,'test.jpg') img.save(imgFile) When I run this, I notice that if I ctrl-V , the image is actually correctly saved on

PUT request for image upload not working in django rest

こ雲淡風輕ζ 提交于 2020-01-13 08:01:26
问题 I am trying to upload an image in django rest using multipart/form-data in a PUT request and Pillow: class ABC(APIView): parser_classes = (MultiPartParser,) def put(self, request): a = Image() a.image_url = request.data["image"] a.save() class Image(models.Model): image_url = models.ImageField(upload_to='static/bills', blank=True) I make a request which is a PUT request and a multipart/form-data. I end up getting a response code of 400 with the message: { "detail": "Multipart form parse error

How to read image from numpy array into PIL Image?

天大地大妈咪最大 提交于 2020-01-11 08:24:21
问题 I am trying to read an image from a numpy array using PIL, by doing the following: from PIL import Image import numpy as np #img is a np array with shape (3,256,256) Image.fromarray(img) and am getting the following error: File "...Image.py", line 2155, in fromarray raise TypeError("Cannot handle this data type") I think this is because fromarray expects the shape to be (height, width, num_channels) however the array I have is in the shape (num_channels, height, width) as it is stored in this

Python——验证码识别 Pillow + tesseract-ocr

岁酱吖の 提交于 2020-01-08 09:05:02
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 简介 图片验证码识别的可以分为几个步骤,一般用 Pillow 库或 OpenCV 来实现,这几个过程是: 灰度处理&二值化 降噪 字符分割 标准化 识别 灰度化:在RGB模型中,如果R=G=B时,则彩色表示一种灰度颜色,其中R=G=B的值叫做灰度值,因此,灰度图像每个像素值只需一个字节存放灰度值(又称强度值、亮度值),灰度范围为0-255。 二值化:二值化可以把灰度图片转换成二值图像,把大于某个临界灰度值的像素灰度设置为灰度极大值,把小于这个值的像素灰度设为灰度极小值,从而实现二值化。 降噪就是把不需要的信息通通去除,比如背景,干扰线,干扰像素等等,只留下需要识别的字符,让图片变成2进制点阵,方便代入模型训练。 灰度处理: 灰度化:在RGB模型中,如果R=G=B时,则彩色表示一种灰度颜色,其中R=G=B的值叫做灰度值,因此,灰度图像每个像素值只需一个字节存放灰度值(又称强度值、亮度值),灰度范围为0-255。 from PIL import Image # 用于打开图片和对图片处理 def img_to_gray(path): """ 图片转灰度 :param path: :return: """ img = Image.open(path) img = img.convert('L') #转灰度 img

Import Image using Pillow : No module named 'PIL'

梦想的初衷 提交于 2020-01-07 03:17:06
问题 Several posts were advising to import Pillow using pip, after having uninstalled both PIL and Pillow, what i did : python -m pip uninstall Pillow (worked) python -m pip uninstall PIL (PIL was not installed) python -m pip install Pillow (worked, i guess it was fine already) Then, according to these posts, using "from PIL import Image" in python should work. I get the error "ImportError: No module named 'PIL'". I tried "import Image" and "from Pillow import Image" but none of that works either.