Code Monkey home page Code Monkey logo

pydecorate's Introduction

pydecorate

https://github.com/pytroll/pydecorate/workflows/CI/badge.svg?branch=main https://coveralls.io/repos/github/pytroll/pydecorate/badge.svg?branch=main

Pydecorate is a package for decorating PIL images with logos, texts, and color scales.

Originally created by Hrobjartur Thorsteinsson November 2013, from Norrkoping, Sweden

pydecorate's People

Contributors

adybbroe avatar dependabot[bot] avatar djhoese avatar mraspaud avatar peters77 avatar pnuu avatar pre-commit-ci[bot] avatar talonglong avatar thorsteinssonh avatar uhamann avatar zmoon avatar zxdawn avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pydecorate's Issues

Background always black

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:

decorated

Expected: White/yellow background for logo/text.

Environment: pydecorate-0.1.0, aggdraw-1.3. It worked fine with aggdraw-1.1-20051010.

fromstring deprecated

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

"OSError: cannot load font (no text renderer)"

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.

pydecorate.DecoratorAGG: How to put text/colorbar outside of image and control width of colorbar.

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.

pkg_resources is deprecated as an API

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.

Incorrect font parameter description in documentation for add_text

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.