0.5.0 • Published 2 years ago

@string-bean/hexo-image-toolkit v0.5.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Hexo Image Toolkit

npm (scoped) GitHub Workflow Status NPM

Hexo tag plugin for converting & resizing images and generating associated markup.

Install

Install the package:

npm install -S @string-bean/hexo-image-toolkit

Then ensure that you have asset folders enabled in your Hexo _config.yml:

post_asset_folder: true

Usage

Given the following Markdown with example.jpg having a size of 2048x1536 pixels:

{% post_img example.jpg title="An example image" retina %}

The following HTML will be generated:

<figure class="image">
  <picture>
    <source
      srcset="/post-path/example@2x.webp 2x, /post-path/example.webp"
      type="image/webp"
    />
    <img
      src="/post-path/example.jpg"
      alt="An example image"
      width="1024"
      height="768"
    />
  </picture>

  <figcaption>
    <span>An example image</span>
  </figcaption>
</figure>

Along with the following image assets:

  • /post-path/example@2x.webp - sized 2048x1536
  • /post-path/example.webp - sized 1024x768
  • /post-path/example.jpg - sized 1024x768

Options

NameDefaultDescription
titlerequiredTitle to use in the figure caption.
alttitle valueText to use for the alt tag. If not supplied then the title value will be used.
retinafalseIf true then the
widthnone (auto)Fixed width to resize the image to.
heightnone (auto)Fixed height to resize the image to.

Image Sizing

By default, the size of the input image is used for both the WEBP and fallback images. If the retina flag is set then this size will be used for the 2x image and fallback images generated at a quarter of the resolution.

For example, given an input image with a size of 2000x1000 pixels:

retinawidthheight2x webp SizeStandard webp SizeFallback Sizeimg Tag Size
falseunsetunsetnone2000x10002000x10002000x1000
false400unsetnone400x200400x200400x200
falseunset2000none4000x20004000x20004000x2000
false1500300none1500x3001500x3001500x300
trueunsetunset2000x10001000x5001000x5001000x500
true400unset400x200200x100200x100200x100
0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

3 years ago

0.2.0

4 years ago

0.3.1

3 years ago

0.1.10

4 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago