GithubHelp home page GithubHelp logo

cardridge / octopress-thumbnail Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rcmdnk/octopress-thumbnail

0.0 2.0 0.0 8 KB

Thumbnail tag for Octopress (Jekyll)

License: MIT License

Ruby 86.25% CSS 13.75%

octopress-thumbnail's Introduction

octopress-thumbnail

Thumbnail tag for Octopress (Jekyll).

Requirement

octopress-thumbnail uses ImageMagick.

To install it, in Mac with Homebrew:

$ brew install imagemagick

In Cygwin with apt-cyg (in Windows):

$ apt-cyg install ImageMagick

or as you like.

Installation

Copy plugins/thumbnail.rb to your plugins directory.

Usage

After installing thumbnail.rb, you can use thumbnail tag in your Markdown files.

Usage is almost same as img tag in Octopress.

A syntax is:

{% thumbnail [class name(s)] [http[s]:/]/path/to/image [width [height]] [title text | "title text" ["alt text"]] %}

This is same as img tag, but a class name with a size or width and height are necessary.

Examples:

  • {% thumbnail /images/big_image.jpg 100 100 %}

This makes /images/thumbnail/big_image_100_100.jpg with 100x100px size, and adds HTML:

<img src="/images/thumbnail/big_image_100_100.jpg" width="100" height="100">
  • {% thumbnail my-thumbnail /images/big_image.jpg %}

You can use class name to define the size. To use the class, define width/height in your _config.yml like:

# Thumbnails
thumbnails:
  - my-thumbnail
my-thumbnail-width: 200
my-thumbnail-height: 200

Give class name to thumbnails, and define <class name>-width and <class name>-height.

Then, the tag makes /images/thumbnail/big_image_200_200.jpg with 200x200px size, and adds HTML:

<img class="my-thumbnail" src="/images/thumbnail/big_image_200_200.jpg" width="200" height="200">
  • {% thumbnail my-thumbnail /images/big_image.jpg "This is a thumbnail" "Thumbnail" %}

You can add title/alt like img tag, too. This adds:

<img class="my-thumbnail" src="/images/thumbnail/big_image_200_200.jpg" width="200" height="200" title="This is a thumbnail" alt="Thumbnail">
  • Use a variable as source path

You can use a variable for the source path.

Assume you have following settings in _config.yml:

images:
  - a.jpg
  - b.jpg
  - c.jpg

then, you can use them in your post like:

{% for img in site.images %}
  {% capture imgpath %}/images/{{img}}{% endcapture %}
  {% thumbnail val:imgpath 100 100 %}
{% endfor %}

Put val: if you want to use a variable as a path.

This is same as:

{% thumbnail /images/a.jpg 100 100 %}
{% thumbnail /images/b.jpg 100 100 %}
{% thumbnail /images/c.jpg 100 100 %}

Note:

It keeps a ratio of width/height and doesn't upsize the file, only shrink the file.

  • If the original file is 400x300px, and the thumbnail is 100x100px:
    • Resize it to 133.3x100px, and crop 100x100px from left upper region.
  • If the original file is 300x400px, and the thumbnail is 100x100px:
    • Resize it to 100x133.3px, and crop 100x100px from left upper region.
  • If the original file is 200x50px, and the thumbnail is 100x100px:
    • Crop 100x100px from left upper region.

Note:

If a gif file is given, it just sets width and height and uses the original image. (It is a bit difficult to minify gif automatically.)

Cleanup Tips

If there is already a thumbnail, thumbnail tag doesn't make it.

If you updated the original file, then you need to delete the corresponding thumbnail to update it.

It is useful to modify a cleanup task in your Rakefile of Octopress, like

desc "Clean out caches: .pygments-cache, .gist-cache, .sass-cache, thumbnail"
task :clean do
  rm_rf [Dir.glob(".pygments-cache/**"), Dir.glob(".gist-cache/**"), Dir.glob(".sass-cache/**"), "#{source_dir}/stylesheets/screen.css"]
  rm_rf [Dir.glob("#{source_dir}/images/**/thumbnail")]
end

Then, all thumbnails will be cleaned up by rake clean.

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.