npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

open-weather-image

v4.0.1

Published

A npm package to create images (base64 png) from the open weather API

Downloads

30

Readme

open-weather-image

open-weather-image is a image creation (base64 or buffer (png format)) to show current weather data of a provided area

Forecast data is loaded from OpenWeather API

The theme changes if it's daytime or nighttime as shown below

Daytime

Nighttime

Or alternatively you can include it with a forecast

WithForecast

Optionally if you don't like the default colours, you can customise the theme (Only with solid colours, all arguments are optional, gradients will be added in future version)

Installation

npm:

npm install open-weather-image

bun:

bun add open-weather-image

Usage

First you will need to register and account on OpenWeather to obtain an API key

Recommended to put your API key as an environment variable.

How to Start OpenWeather

Basic Usage

You can output with a buffer or base64 string. Default: "buffer"

Base 64:

import { createWeatherImage } from 'open-weather-image';

const image = await createWeatherImageToday({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Munich',
    output: 'base64',
});

Buffer:

import { createWeatherImage } from 'open-weather-image';

const image = await createWeatherImageToday({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Munich',
    output: 'buffer',
});

With Metric Units

import { createWeatherImage } from 'open-weather-image';

const image = await createWeatherImageToday({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Munich',
    units: 'metric',
});

With Imperial Units

Imperial

Omitting the units property will use the preferred temperature unit of the target country.

import { createWeatherImage } from 'open-weather-image';

const image = await createWeatherImageToday({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Springfield',
    stateCode: 'OR',
    countryCode: 'US',
    units: 'imperial',
});

With Forecast

WithForecast

import { createWeatherImage } from 'open-weather-image';

const image = await createWeatherImage({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Munich',
    withForecast: true,
});

Choosing a Locale

Currently only English and German is supported, and tested with, feel free to contribute with other langauges within the i18n.ts file. Default: "en"

ChangingLocale

import { createWeatherImage } from "open-weather-image"

const image = await createWeatherImage({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Munich',
    withForecast: true,
    locale: "de",
});

Possible Locales (All the ones that don't have full support are disabled)

af - Afrikaans
al - Albanian
ar - Arabic
az - Azerbaijani
bg - Bulgarian
ca - Catalan
cz - Czech
da - Danish
de - German (Full Support)
el - Greek
en - English (Full Support)
eu - Basque
fa - Persian (Farsi)
fi - Finnish
fr - French
gl - Galician
he - Hebrew
hi - Hindi
hr - Croatian
hu - Hungarian
id - Indonesian
it - Italian
ja - Japanese
kr - Korean
la - Latvian
lt - Lithuanian
mk - Macedonian
no - Norwegian
nl - Dutch
pl - Polish
pt - Portuguese
pt_br - Português Brasil
ro - Romanian
ru - Russian
sv, se - Swedish
sk - Slovak
sl - Slovenian
sp, es - Spanish
sr - Serbian
th - Thai
tr - Turkish
ua, uk - Ukrainian
vi - Vietnamese
zh_cn - Chinese Simplified
zh_tw - Chinese Traditional
zu - Zulu

With a Theme

WithTheme

import { createWeatherImage } from 'open-weather-image';

const myTheme = {
    dayThemeRight: '#373CC4',
    forecastBgTheme: '#242424',
    forecastBoxDivider: '#FFFFFF',
    dayThemeText: '#FF00FF',
    dayThemeSymbol: '#00FF00',
};

const image = await createWeatherImage({
    key: process.env.WEATHER_API_KEY,
    cityName: 'Munich',
    withForecast: true,
    theme: myTheme,
});

Importing the theme type in TypeScript

import type { Theme } from 'open-weather-image';

Default Theme

const defaultTheme = {
    dayThemeLeft: '#FFD982',
    dayThemeRight: '#5ECEF6',
    dayThemeText: 'black', // #000000
    dayThemeSymbol: 'black',
    nightThemeLeft: '#25395C',
    nightThemeRight: '#1C2A4F',
    nightThemeText: 'white', // #FFFFFF
    nightThemeSymbol: 'white',
    forecastBgTheme: '#DDDDDD',
    forecastBoxTheme: '#EEEEEE',
    forecastText: 'black',
    forecastSymbolColour: 'black',
    forecastBoxDivider: 'black',
};

Contributing

Before creating an issue, please ensure that it hasn't already been reported/suggested.

You are free to submit a PR to this repo, please fork first, please only communicate in English or German.

License

open-weather-image is available under the MIT license. See the LICENSE.md file for more info.

Copyright © 2022-2024 Kira Kitsune https://kirakitsune.com, All rights reserved.