Pydecorate is a package for decorating PIL images with logos, texts, and color scales.
Originally created by Hrobjartur Thorsteinsson November 2013, from Norrkoping, Sweden
Automatically exported from code.google.com/p/pydecorate
Home Page: http://pydecorate.readthedocs.org/en/latest/
License: GNU General Public License v3.0
The background of a logo or text element is always black. Specifying the background color has no effect.
import numpy as np
from PIL import Image
from pydecorate import DecoratorAGG
import aggdraw
# Create sample image
im = Image.fromarray(np.random.randint(low=0, high=255, size=(480, 640), dtype=np.uint8))
# Add logo & text
deco = DecoratorAGG(image=im)
font = aggdraw.Font('black', '/usr/share/fonts/dejavu/DejaVuSansCondensed.ttf', size=48)
deco.add_logo('mylogo.png', bg='white')
deco.add_text('Test Label', font=font, bg='yellow', height=None)
im.save('decorated.png')
Result:
Expected: White/yellow background for logo/text.
Environment: pydecorate-0.1.0, aggdraw-1.3. It worked fine with aggdraw-1.1-20051010.
With this piece of code
img = Image.open(imgfile)
dc = DecoratorAGG(img)
dc.add_logo(smhilogo, height=80.0)
...I get some deprecation warnings:
/local_disk/src/pydecorate/pydecorate/__init__.py:270: DeprecationWarning:
tostring() is deprecated. Please call tobytes() instead.
return aggdraw.Draw(image)
Code works fine, but we need to fix this for the future!
Original issue reported on code.google.com by [email protected]
on 13 Nov 2014 at 11:59
An error occurred during the use of pydecorate, and I did not go to the custom font-related configuration.
all are configured by default.
File "C:\ProgramData\Miniconda3\envs\py\lib\site-packages\satpy\writers\__init__.py", line 325, in add_scale
dc.add_scale(**scale)
File "C:\ProgramData\Miniconda3\envs\py\lib\site-packages\pydecorate\decorator_agg.py", line 30, in add_scale
self._add_scale(colormap, **kwargs)
File "C:\ProgramData\Miniconda3\envs\py\lib\site-packages\pydecorate\decorator_base.py", line 419, in _add_scale
self._get_current_font()
File "C:\ProgramData\Miniconda3\envs\py\lib\site-packages\pydecorate\decorator_base.py", line 236, in _get_current_font
self.style["font"] = self._load_font()
File "C:\ProgramData\Miniconda3\envs\py\lib\site-packages\pydecorate\decorator_agg.py", line 38, in _load_font
return aggdraw.Font(
OSError: cannot load font (no text renderer)
Env: Windows; aggdraw 1.3.16; pydecorate 0.3.4.
I am working with pydecorate to add text and colorbar to images . I am working with this tutorial:
https://pydecorate.readthedocs.io/en/latest/usage.html
I am using this code:
from PIL import Image
from pydecorate import DecoratorAGG
import aggdraw
from trollimage.colormap import rdbu
import matplotlib.pyplot as plt
filepath = r'path\to\file.tif
img = Image.open(filepath)
dc = DecoratorAGG(img)
dc.write_vertically()
dc.align_left()
font=aggdraw.Font("black", r'C:\Windows\Fonts\times.ttf', size = 115)
dc.add_text(
'text line 1\nline 2 or text\nThis is also text',
font = font)
dc.add_scale(rdbu, extend = True)
imgplot = plt.imshow(img) # image will not display in plots window.
This creates text and a colorbar like I want, but the width of the colorbar seems to be dictated by the width of the text above it. Is there some way to manually set the width of the colorbar?
Also, is there some way to display the colorbar next to the image, as opposed to on the edge of the image? Should I do this by simply adding a border?
Thanks for your help.
Probably due to newer numpy.
See failures in #25
Warning from the test suite:
pydecorate\decorator_agg.py:21
pydecorate\pydecorate\decorator_agg.py:21: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
from pkg_resources import resource_filename
I also noticed it is not currently listed as a dep, though it is currently required.
Due to this line
pydecorate/pydecorate/decorator_base.py
Line 357 in 4d21d61
(Image.ANTIALIAS
was removed.)
Exception:
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
The font parameter for add_text does not take a font object as parameter as described by the documentation, but rather a string object describing the path to the font to use.
Font parameters such as size are then passed as additional optional parameters in the add_text call. An example for correct usage would be:
dc.add_text("IR Temperature [C]", font="/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf", font_size=12, height=25)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.