Git Product home page Git Product logo

image_optim-jekyll-plugin's Introduction

image_optim-jekyll-plugin

A simple Jekyll plugin (forked from chrisanthropic/image_optim-jekyll-plugin) to optimize images using image_optim.


Usage

Runs automatically when you jekyll build:

# Add a new image to the site.
cp ~/downloads/cheese-cat-fail.jpg ~/website/images/

# Build the site; image_optim-jekyll-plugin runs automatically.
~/website:master > bundle exec jekyll build
Configuration file: /home/chris/website/_config.yml
            Source: /home/chris/website
       Destination: /home/chris/website/_site
      Generating...
Optimizing images/cheese-cat-fail.jpg
                    done.
 Auto-regeneration: disabled. Use --watch to enable.

Let's look at what changed:

~/website:master > git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   _image_optim_cache.yml

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	_image_optim_archive/cheese-cat-fail-2016-10-14-09-10-15-02de96ea1978a39c4b7860e8d1125773.jpg
	images/cheese-cat-fail.jpg

no changes added to commit (use "git add" and/or "git commit -a")

You see three changes:

  1. New file: images/cheese-cat-fail.jpg, which I added manually to my image root (assets/img). This image is automatically optimized in-place by the plugin. Repeat: this is not the original file, as optimization is done in-place.
  2. New file: _image_optim_archive/cheese-cat-fail-2016-10-14-09-10-15-02de96ea1978a39c4b7860e8d1125773.jpg. This is a copy of the original file (before optimization). It's tagged with the date/time of optimization as well as the MD5 of the original content.
  3. Changed file: _image_optim_cache.yml is for internal use by the plugin (it keeps track of which images have been optimized, and when).

Installation

Add to your Gemfile:

gem 'image_optim'
gem 'image_optim_pack'

Copy image_optim.rb to your _plugins directory.


Configuration

Note: All paths are relative to the site root.

archive_dir: Directory in which copies of original images are saved for future reference.

  • Type: string
  • Default: "_image_optim_archive"

cache_file: Path to a file where the plugin keeps its internal metadata.

  • Type: string
  • Default: "_image_optim_cache.yml"

image_glob: Path that specifies which images are to be optimized.

  • Type: string
  • Default: "images/**/*.{gif,jpg,jpeg,png}"

You can override configuration defaults by keying them under image_optim in _config.yml. Here's an example:

config.yml:
# Site stuff.
title: My Cat Blog
baseurl: "/cats"
permalink: "/:year/:title.html"

# Deployment exclusions.
exclude:
  - .gitignore
  - Gemfile
  - Gemfile.lock

# image_optim-jekyll-plugin customizations.
image_optim:
  archive_dir: "assets/full-res-kittens"
  cache_file: "tmp/kitty-cache.yml"
  image_glob: "assets/img/**/cat-*.{gif,png,jpg,jpeg}"

Note: Your use case will dictate whether you choose to include or exclude your archive_dir and/or cache_file in source control.


License

MIT

image_optim-jekyll-plugin's People

Contributors

amalfra avatar chrisanthropic avatar cmtonkinson avatar wei-xia avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.