2.1.3 • Published 4 years ago

kopiro-tommy v2.1.3

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Tommy: web assets optimverter

Tommy will process, optimize and convert all your static assets ready to use for the web.

npm version docker version

Arguments

  • --src specify the source directory (where your assets are located)
  • --dst specify the destination directory (where your assets will be generated)

Optional argumenmts

  • --force regenerate all assets ignoring cache
  • --config specify a JSON file containing an extension to the configuration
  • --webserver will spawn an HTTP webserver that access via POST / a request to run
  • --port is the webserver port (default: 80)
  • --watch will enable a persistent watch over the src directory to detect instant file changes

⚡️️️ Always set --dst option to an empty directory: this directory should only be used by Tommy because files in could be potentially deleted if Tommy is started with a weird configuration or a corrupted database ⚡️

How to: run with Docker

The main advantage of using Tommy is that all dependencies used to process/convert entities are encapsulated into a docker image.

For this reason, you should use the docker run command to use Tommy in the original way it was created.

docker run \
-v "$(pwd)/test/src":/src \
-v "$(pwd)/test/dst":/dst \
-v "$(pwd)/config.json:/root/config.json" \
kopiro/tommy:latest \
--src /src \
--dst /dst \
--config /root/config.json

Explanation of mounts:

  • -v "$(pwd)/test/src":/src mount the source directory (where your assets are located) into container /src
  • -v "$(pwd)/test/dst":/dst mount the destination directory (where your assets will be generated) into container /dst
  • -v "$(pwd)/config.json:/root/config.json" mount your (optional) configuration JSON file into container /root/config.json

How to: run in MacOS

You can also use the native NPM package on OSX.

Installation

npm -g i kopiro-tommy

Run

tommy --src ./test/src --dst ./test/dst

Configuration

By providing a JSON file to --config, you configuration will be extended with the default one.

tommy --config config.json

Example:

{
  "processor.resize": {
    "enabled": false
  },
  "processor.resize": {
    "enabled": true,
    "suffix": "-resized-${i}.${ext}",
    "dimensions": [100, 300],
    "quality": 60
  },
  "ignore": [".dockerignore"]
}

First-level keys

KeyTypeDescriptionDefault
ignorestring[]Pattern to ignoresee config.json

Available services

Images

KeyApplies toDescription
processor.resize*resize the image in differents formats
processor.image*optimize the image
processor.lazyLoadBlurried*generates a very small blurried image that can be used before loading final image in lazy load
converter.webp*converts to WEBP format
tester.image*generates a sample HTML page to test all differents formats
processor.jpg*.jpgoptimizes the JPG using jpegoptim
processor.png*.pngoptimizes the PNG using pngquant
processor.gif*.gifoptimizes the GIF using gifsicle
processor.svg*.svgoptimizes the SVG using svgo
processor.favicon/favicon.pnggenerates all images/icons needed in various browsers for the favicon

Videos

KeyApplies toDescription
processor.poster*generates a representative poster image from the video to use as picture before loading the video.
processor.videoThumbs*generates N different thumbs from the video
converter.webm*converts to WEBM format
converter.h264_mp4*converts to H264 using MP4 container
converter.av1_mp4*converts to AV1 using MP4 container. currently disabled by default because it's very very slow
converter.hevc_mp4*converts to HEVC using MP4 container
tester.video*generates a sample HTML page to test all differents formats

Fonts

KeyApplies toDescription
converter.ttf*converts to TTF format
converter.otf*converts to OTF format
converter.eot*converts to EOT format
converter.svg*converts to SVG format
converter.woff*converts to WOFF format
converter.woff2*converts to WOFF2 format
tester.font*generates a sample HTML page to test all differents formats

Audios

KeyApplies toDescription
converter.mp3*converts to MP3 format

Disabling service

By settings enabled: false in a key, you'll disable that service.

...
"processor.resize": {
   "enabled": false
}
...

Specific configurations for services

processor.resize

KeyTypeDescriptionDefault
dimensionsnumber[]Dimensions of resized images in PX (longest side)[200,400,800,1200]
qualitynumberQuality of images80
suffixstringSuffix to Applies to new files"-resized-${i}.${ext}"

processor.image

KeyTypeDescriptionDefault
qualitynumberQuality of image80

processor.videoThumbs

KeyTypeDescriptionDefault
countnumberHow many thumbnails extract5
sizenumberLength of longest side400
qualitynumberQuality of image80
suffixstringSuffix to Applies to new files"-thumb-\${i}.jpg"

processor.lazyLoadBlurried

KeyTypeDescriptionDefault
sizenumberLength of longest side10
suffixstringSuffix to Applies to new files"-blurried.jpg"

processor.poster

KeyTypeDescriptionDefault
suffixstringSuffix to Applies to new files"-poster.jpg"

processor.favicon

KeyTypeDescriptionDefault
webmanifestobjectJSON object to extend for the site.webmanifest. Set to false to disable generation.see config.json
browserconfigboolSet to false to disable generation of browserconfig.xmltrue
testboolSet to false to disable HTML test page (favicon.html)true
tileColorstringColor of the tile for Windows"#336699"
themeColorstringColor of the theme for Chrome Mobile"#336699"

convert.{webm,*_mp4}

These are the general settings used for video. You can override manually in every section

KeyTypeDescriptionDefault
audioCodecstringThe coded to use for audionull
crfnumberThe range of the CRF scale is 0–51, where 0 is lossless, 23 is the default, and 51 is worst quality possible.23
pixelFormatstringIt uses full resolution for brightness and a smaller resolution for color."yuv420p"
mapMetadatastringChoose to keep/remove metadata"-1"
movFlagsstringMovie flags to pass to ffmpeg"+faststart"
presetstringWill provide a certain encoding speed to compression ratio."medium"

converter.webm

KeyTypeDescriptionDefault
videoCodecstringsee general section"libvpx-vp9"

converter.h264_mp4

KeyTypeDescriptionDefault
videoCodecstringsee general section"libx264"

converter.av1_mp4

KeyTypeDescriptionDefault
videoCodecstringsee general section"libaom-av1"
audioCodedstringsee general section"libopus"
crfnumbersee general section (note: this value is higher due te different scale of this algorithm)50

converter.hvec_mp4

KeyTypeDescriptionDefault
videoCodecstringThe coded to use for video"libx265"

Howto: testing locally

You can use the command npm run test-docker to build the image and test against a test directory.

If you need samples, run npm run download-samples

License

MIT

2.1.3

4 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago