open-weather-image
TypeScript icon, indicating that this package has built-in type declarations

3.0.2 • Public • Published

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 install 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

With Metric Units

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

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

With Imperial Units

Imperial

Note: if a country by default uses Imperial or Metric units, it will default to it (e.g. in the US: Imperial, in UK: Metric)

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

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

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

With Forecast

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

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

With a Theme

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

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

const image = await createWeatherImage({
    key: 'YOUR API KEY',
    cityName: 'Adelaide',
    withForecast: true,
    theme: myTheme,
});

Result:

WithTheme

Importing the theme type (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, english and german is the preferred languages.

License

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

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

Package Sidebar

Install

npm i open-weather-image

Weekly Downloads

1

Version

3.0.2

License

MIT

Unpacked Size

126 kB

Total Files

10

Last publish

Collaborators

  • kirakitsune