Specify Docs
Specify ↗︎Changelog ↗︎Guide ↗︎
V2
V2
  • Getting started
    • Introduction
    • What is Specify?
    • Pulling your first tokens with the CLI
    • Glossary
  • Collect
    • What is a Source?
    • Available sources
      • Figma Variables & Styles
      • Tokens Studio
  • Distribute
    • What is a Destination?
    • Available destinations
      • GitHub
      • Specify CLI
      • Specify SDK
      • HTTP API
  • Concepts
    • Overview
    • Parsers Engine
    • SDTF Client
      • SDTF Engine
    • Specify Design Token Format
  • Guides
    • Configuration file 101
    • Specify CLI usage 101
      • Getting started
      • Authentication
      • Generate Files
    • Specify SDK usage 101
      • Getting started
      • Retrieving and working with the tokens
      • Updating tokens
      • Converting a token to XXX
      • Executing generation parsers
    • Specify SDK Cheatsheet
    • Manage font files
    • Querying a SDTF graph
  • Reference
    • Parsers Engine
    • Parsers
      • change-case
      • convert-color
      • convert-dimension
      • make-line-height-relative
      • filter
      • register-view
      • select-modes
      • prefix-by
      • suffix-by
      • replace-string
      • to-css-custom-properties
      • to-css-text-style
      • to-css-font-import
      • to-flutter
      • to-javascript
      • to-json
      • to-json-list
      • to-kotlin
      • to-react-native
      • to-scss-mixin-text-style
      • to-scss-map
      • to-sdtf
      • to-style-dictionary
      • to-swift
      • to-tailwind
      • to-typescript
      • svgo
      • svg-to-jsx
      • svg-to-tsx
      • to-svg-file
      • to-bitmap-file
      • to-file
    • Specify SDK
      • SpecifyClient
      • SDTFClient
      • Converters
        • CSS
      • ParsersEngineResults
    • SDTF Engine
      • Query API
      • Mutation API
      • SDTF Query Language
      • SDTF QueryResult
      • TokenState
        • Stateful Value
    • HTTP API
      • POST /parsers-engine-rpc
    • Specify CLI
  • Resources
    • Parser Rules templates
      • CSS Custom Properties
      • Tailwind
      • React Native
      • Flutter
      • SDTF
      • JSON
    • Specify CLI VS Specify SDK
    • Playground
    • Best practices
  • Useful links
    • Discord
    • YouTube
    • Twitter
    • Help Center
    • Canny
Powered by GitBook
On this page
  • Interface
  • Options
  • Basic usage - single mode
  • Advanced usage - Several modes by definition (@1x, @2x...)

Was this helpful?

Export as PDF
  1. Reference
  2. Parsers

to-bitmap-file

This parser helps you generate PNG and JPG files from your bitmap assets.

Interface

interface parser {
  name: 'to-bitmap-file';
  options: {
    filenameTemplate: string;
  };
  output: {
    type: 'directory';
    directoryPath: string;
  };
};

Options

Parameter
Required
Type
Default
Description

filenameTemplate

false

string

"{{parents}}/{{name}}[-{{mode}}]{{extension}}"

The mustache template used to generate the file path to write to the file system. Available variables: parents: group and collection names of the token's parents name: the name of the asset token mode: the name of the current mode extension: the file extension extracted from the token

Basic usage - single mode

{
  "assets": {
    "image": {
      "$type": "bitmap",
      "$value": {
        "1x": {
          "url": "<url-of-your-bitmap-file>",
          "format": "png",
          "width": 623,
          "height": 415,
          "variationLabel": null
        }
      }
    }
  }
}
.specifyrc.json
{
  "version": "2",
  "repository": "@organization/repository",
  // Only use the personalAccessToken when working with the CLI
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "Generate images",
      "parsers": [
        {
          "name": "to-bitmap-file",
          "output": {
            "type": "directory",
            "directoryPath": "public"
          }
        }
      ]
    }
  ]
}

This will generate a single bitmap file like so:

  • public/assets/image.png

Advanced usage - Several modes by definition (@1x, @2x...)

Our bitmap is named "image", is in a group named "assets", and has 2 modes for each definition parameter: 1x and 2x.

By default, this parser will generate the following output: {directoryPath}/{groups}/{bitmapName}.{png|jpg}

{
  "assets": {
    "image": {
      "$type": "bitmap",
      "$value": {
        "1x": {
          "url": "<url-of-your-bitmap-file>",
          "format": "png",
          "width": 623,
          "height": 415,
          "variationLabel": null
        },
        "2x": {
          "url": "<url-of-your-bitmap-file>",
          "format": "png",
          "width": 1246,
          "height": 830,
          "variationLabel": null
        }
      }
    }
  }
}
.specifyrc.json
{
  "version": "2",
  "repository": "@organization/repository",
  // Only use the personalAccessToken when working with the CLI
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "Generate images",
      "parsers": [
        {
          "name": "to-bitmap-file",
          "output": {
            "type": "directory",
            "directoryPath": "public"
          }
        }
      ]
    }
  ]
}

This will generate the following bitmap files:

  • public/assets/image-1x.png

  • public/assets/image-2x.png

Previousto-svg-fileNextto-file

Last updated 1 year ago

Was this helpful?