jekyll_picture_tag 1.7.0 → 1.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.solargraph.yml +15 -0
- data/.travis.yml +4 -7
- data/Dockerfile +9 -0
- data/docs/Gemfile +4 -0
- data/docs/Gemfile.lock +249 -0
- data/docs/_config.yml +13 -0
- data/docs/_layouts/directory.html +32 -0
- data/docs/assets/style.css +31 -0
- data/{contributing.md → docs/contributing.md} +57 -15
- data/docs/{examples/_data/picture.yml → example_presets.md} +36 -25
- data/docs/global_configuration.md +61 -3
- data/docs/index.md +114 -0
- data/docs/installation.md +36 -21
- data/docs/migration.md +4 -0
- data/docs/notes.md +64 -58
- data/docs/output.md +63 -0
- data/docs/presets.md +175 -221
- data/docs/releases.md +64 -0
- data/docs/usage.md +91 -79
- data/jekyll_picture_tag.gemspec +3 -1
- data/lib/jekyll_picture_tag.rb +27 -10
- data/lib/jekyll_picture_tag/defaults/global.yml +2 -0
- data/lib/jekyll_picture_tag/defaults/presets.yml +2 -0
- data/lib/jekyll_picture_tag/generated_image.rb +105 -19
- data/lib/jekyll_picture_tag/instructions.rb +1 -0
- data/lib/jekyll_picture_tag/instructions/arg_splitter.rb +68 -0
- data/lib/jekyll_picture_tag/instructions/configuration.rb +47 -11
- data/lib/jekyll_picture_tag/instructions/html_attributes.rb +14 -8
- data/lib/jekyll_picture_tag/instructions/preset.rb +34 -14
- data/lib/jekyll_picture_tag/instructions/set.rb +18 -8
- data/lib/jekyll_picture_tag/instructions/tag_parser.rb +59 -69
- data/lib/jekyll_picture_tag/output_formats/basic.rb +35 -6
- data/lib/jekyll_picture_tag/output_formats/data_attributes.rb +4 -1
- data/lib/jekyll_picture_tag/router.rb +16 -0
- data/lib/jekyll_picture_tag/source_image.rb +6 -1
- data/lib/jekyll_picture_tag/srcsets/basic.rb +45 -19
- data/lib/jekyll_picture_tag/srcsets/pixel_ratio.rb +1 -3
- data/lib/jekyll_picture_tag/srcsets/width.rb +1 -1
- data/lib/jekyll_picture_tag/utils.rb +18 -0
- data/lib/jekyll_picture_tag/version.rb +1 -1
- data/readme.md +43 -200
- metadata +49 -13
- data/docs/examples/_config.yml +0 -10
- data/docs/examples/post.md +0 -46
- data/docs/readme.md +0 -23
data/docs/releases.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
---
|
2
|
+
---
|
3
|
+
# Release History
|
4
|
+
|
5
|
+
* 1.10.1 July 2, 2020
|
6
|
+
* Bugfix for erroneously regenerated images
|
7
|
+
* 1.10.0 May 11, 2020
|
8
|
+
* **Image Cropping support!** access the power of ImageMagick's `crop` function.
|
9
|
+
* Don't issue a warning when `default` preset is not found.
|
10
|
+
* Documentation improvements
|
11
|
+
* 1.9.0 Feb 2, 2020
|
12
|
+
* Add `fast_build` global setting
|
13
|
+
* Add `disabled` global setting
|
14
|
+
* Reduce unnecessary disk IO; sites with many source images should see build times improve when
|
15
|
+
no new images need to be generated.
|
16
|
+
* Add support for empty attributes; specifically so best-practice for decorative images (`alt=""`)
|
17
|
+
is possible.
|
18
|
+
* 1.8.0 Nov 25, 2019
|
19
|
+
* Add `data_sizes` setting for the `data_` family of output formats.
|
20
|
+
* 1.7.1 Nov 14, 2019
|
21
|
+
* Fix some HTML attribute related bugs
|
22
|
+
* Add a few items to the FAQ
|
23
|
+
* 1.7.0 Aug 12, 2019
|
24
|
+
* Add support for setting generated image quality, either generally or specific to given
|
25
|
+
formats.
|
26
|
+
* Add support for spaces and other url-encoded characters in filenames
|
27
|
+
* Documentation restructure - Moved it out of the wiki, into the `docs` folder.
|
28
|
+
* Bugfix: Fallback image width will now be checked against source image width.
|
29
|
+
* Bugfix: Minor fix to nomarkdown wrapper output
|
30
|
+
* link_source will now target the base source image, rather than finding the biggest one.
|
31
|
+
* Remove fastimage dependency, add addressable dependency.
|
32
|
+
* Moderately significant refactoring and code cleanup
|
33
|
+
* Decent set of tests added
|
34
|
+
* 1.6.0 Jul 2, 2019:
|
35
|
+
* Missing Preset warning respects `data_dir` setting
|
36
|
+
* Add `continue_on_missing` option
|
37
|
+
* 1.5.0 Jun 26, 2019:
|
38
|
+
* better `{::nomarkdown}` necessity detection
|
39
|
+
* allow user to override `{::nomarkdown}` autodetection
|
40
|
+
* 1.4.0 Jun 26, 2019:
|
41
|
+
* Rename gem from `jekyll-picture-tag` to `jekyll_picture_tag`, allowing us to use rubygems again.
|
42
|
+
* Add new output format: `naked_srcset`.
|
43
|
+
* 1.3.1 Jun 21, 2019: Bugfix
|
44
|
+
* 1.3.0 Jun 7, 2019:
|
45
|
+
* Initial compatibility with Jekyll 4.0
|
46
|
+
* bugfixes
|
47
|
+
* change to generated image naming-- The first build after this update will be longer, and you
|
48
|
+
might want to clear out your generated images.
|
49
|
+
* 1.2.0 Feb 9, 2019:
|
50
|
+
* Add nomarkdown fix
|
51
|
+
* noscript option
|
52
|
+
* relative url option
|
53
|
+
* anchor tag wrappers
|
54
|
+
* 1.1.0 Jan 22, 2019:
|
55
|
+
* Add direct_url markup format,
|
56
|
+
* auto-orient images before stripping metadata
|
57
|
+
* 1.0.2 Jan 18, 2019: Fix ruby version specification
|
58
|
+
* 1.0.1 Jan 13, 2019: Added ruby version checking
|
59
|
+
* **1.0.0** Nov 27, 2018: Rewrite from the ground up. See the [migration guide]({{ site.baseurl }}/migration).
|
60
|
+
* 0.2.2 Aug 2, 2013: Bugfixes
|
61
|
+
* 0.2.1 Jul 17, 2013: Refactor again, add Liquid parsing.
|
62
|
+
* 0.2.0 Jul 14, 2013: Rewrite code base, bring in line with Jekyll Image Tag.
|
63
|
+
* 0.1.1 Jul 5, 2013: Quick round of code improvements.
|
64
|
+
* 0.1.0 Jul 5, 2013: Initial release.
|
data/docs/usage.md
CHANGED
@@ -1,131 +1,143 @@
|
|
1
|
-
|
1
|
+
---
|
2
|
+
---
|
2
3
|
|
3
|
-
|
4
|
-
is the base image:
|
4
|
+
# How to use the Liquid Tag:
|
5
5
|
|
6
|
-
|
6
|
+
## Format:
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
{% raw %}
|
9
|
+
`{% picture [preset] (image) [crop] [alternate images & crops] [attributes] %}`
|
10
|
+
{% endraw %}
|
11
|
+
|
12
|
+
The only required argument is the base image. Line breaks and extra spaces are fine, and you can
|
13
|
+
use liquid variables anywhere.
|
10
14
|
|
11
15
|
## Examples:
|
12
16
|
|
17
|
+
{% raw %}
|
13
18
|
`{% picture example.jpg %}`
|
14
19
|
|
15
|
-
`{% picture thumbnail example.jpg %}`
|
20
|
+
`{% picture thumbnail example.jpg 1:1 --alt Example Image %}`
|
21
|
+
|
22
|
+
`{% picture example.jpg 16:9 north --picture class="attribute-demo" %}`
|
16
23
|
|
17
24
|
`{% picture blog_index {{ post.image }} --link {{ post.url }} %}`
|
18
25
|
|
19
26
|
`{% picture "some example.jpg" mobile: other\ example.jpg %}`
|
20
27
|
|
21
|
-
```
|
22
|
-
{% picture
|
23
|
-
hero
|
24
|
-
example.jpg
|
25
|
-
|
26
|
-
|
27
|
-
--
|
28
|
+
```md
|
29
|
+
{% picture
|
30
|
+
hero
|
31
|
+
example.jpg 16:9 east
|
32
|
+
tablet: example_cropped.jpg 3:2 east
|
33
|
+
mobile: example_cropped_more.jpg 1:1-50+0 east
|
34
|
+
--alt Happy Puppy
|
35
|
+
--picture class="hero"
|
28
36
|
--link /
|
29
37
|
%}
|
30
38
|
```
|
31
39
|
|
40
|
+
{% endraw %}
|
41
|
+
|
32
42
|
## Argument reference
|
33
43
|
|
34
|
-
|
44
|
+
Given in order:
|
35
45
|
|
36
|
-
|
46
|
+
- **Preset**
|
37
47
|
|
38
|
-
|
48
|
+
Select a [markup preset]({{ site.baseurl }}/presets#markup-presets), or omit to use the `default` preset. Presets
|
49
|
+
are collections of settings that determine nearly everything about JPT's output, from the image
|
50
|
+
formats used to the exact format your markup will take.
|
39
51
|
|
40
|
-
|
41
|
-
[preset](https://github.com/rbuchberger/jekyll_picture_tag/wiki/Writing-Presets) to use, or leave
|
42
|
-
blank for the `default` preset.
|
52
|
+
- **Base Image** (Required)
|
43
53
|
|
44
|
-
|
54
|
+
Can be any raster image (as long as you have the required ImageMagick delegate). Relative to
|
55
|
+
jekyll's root directory, or the `source` [setting]({{ site.baseurl }}/global_configuration) if you've configured it.
|
45
56
|
|
46
|
-
|
57
|
+
For filenames with spaces, either use double quotes (`"my image.jpg"`) or a backslash (`my\ image.jpg`).
|
47
58
|
|
48
|
-
|
49
|
-
(as long as imagemagick understands it).
|
59
|
+
- **Crop**
|
50
60
|
|
51
|
-
|
61
|
+
**Check the [ installation guide ](installation) before using this feature.**
|
52
62
|
|
53
|
-
|
63
|
+
Crop an image to a given aspect ratio or size. This argument is given as a `geometry` and
|
64
|
+
(optionally) a `gravity`, which can appear in either order and are thin wrappers around
|
65
|
+
ImageMagick's [geometry](http://www.imagemagick.org/script/command-line-processing.php#geometry)
|
66
|
+
and [gravity](http://www.imagemagick.org/script/command-line-options.php#gravity) settings. The
|
67
|
+
values given here will override the preset settings (if present), can be given after every image,
|
68
|
+
and apply only to the preceding image.
|
54
69
|
|
55
|
-
|
70
|
+
Geometry can take many forms, but most likely you'll want to set an aspect ratio-- given in the
|
71
|
+
standard `width:height` ratio such as `3:2`. Gravity sets which portion of the image to keep, and
|
72
|
+
is given in compass directions (`north`, `southeast`, etc) or `center` (default). Cropping happens
|
73
|
+
before resizing; the preset `widths` setting is a post-crop value.
|
56
74
|
|
57
|
-
|
58
|
-
(
|
59
|
-
|
75
|
+
If you'd like more fine-grained control, this can be offset by appending `+|-x` and (optionally)
|
76
|
+
`y` pixel values to the _geometry_ (not the gravity!). Example: `1:1+400 west` means "Crop to a
|
77
|
+
1:1 aspect ratio, starting 400 pixels from the left side.", and `north 3:2+0+100` means "Crop to
|
78
|
+
3:2, starting 100 pixels from the top." These can get a bit persnickety; there's nothing to stop
|
79
|
+
you from running off the side of the image. Pay attention.
|
60
80
|
|
61
|
-
|
62
|
-
|
63
|
-
that evaluates true.
|
81
|
+
For detailed documentation, see ImageMagick's
|
82
|
+
[crop](http://www.imagemagick.org/script/command-line-options.php#crop) tool.
|
64
83
|
|
65
|
-
|
84
|
+
_Note:_ If you do a lot of trial and error with these, it's a good idea to manually delete your
|
85
|
+
generated images folder more often as each change will build a new set of images without removing
|
86
|
+
the old ones.
|
66
87
|
|
67
|
-
|
68
|
-
set in a preset. They can take a few different formats:
|
88
|
+
- **Alternate images**
|
69
89
|
|
70
|
-
|
90
|
+
_Format:_ `(media query preset): (filename) (...)`
|
71
91
|
|
72
|
-
|
92
|
+
_Example:_ `tablet: img_cropped.jpg mobile: img_cropped_more.jpg`
|
73
93
|
|
74
|
-
|
94
|
+
Optionally specify any number of alternate base images for given [screen
|
95
|
+
sizes]({{ site.baseurl }}/presets/#media-presets) (specified in `_data/picture.yml`). This is called [art
|
96
|
+
direction](http://usecases.responsiveimages.org/#art-direction), and is one of JPT's strongest
|
97
|
+
features.
|
75
98
|
|
76
|
-
|
77
|
-
|
99
|
+
Give your images in order of ascending specificity (The first image is the most general). They will
|
100
|
+
be provided to the browser in reverse order, and it will select the first one with an applicable
|
101
|
+
media query.
|
78
102
|
|
79
|
-
|
80
|
-
files and you are using Kramdown (Jekyll's default markdown parser.)
|
81
|
-
##### `--alt`
|
82
|
-
|
83
|
-
*Format:* `--alt (alt text)`
|
103
|
+
- **Attributes**
|
84
104
|
|
85
|
-
|
105
|
+
Optionally specify any number of HTML attributes, or an href target. These will be added to any
|
106
|
+
attributes you've set in a preset.
|
86
107
|
|
87
|
-
|
88
|
-
|
89
|
-
##### `--(element)`
|
108
|
+
- **`--link`**
|
90
109
|
|
91
|
-
|
110
|
+
_Format:_ `--link (some url)`
|
92
111
|
|
93
|
-
|
112
|
+
_Examples_: `--link https://example.com`, `--link /blog/some_post/`
|
94
113
|
|
95
|
-
|
114
|
+
Wrap the image in an anchor tag, with the `href` attribute set to whatever value you give it.
|
115
|
+
This will override automatic source image linking, if you have enabled it.
|
96
116
|
|
97
|
-
|
98
|
-
|
99
|
-
* `source`
|
100
|
-
* `a` (anchor tag)
|
101
|
-
* `parent`
|
117
|
+
**Note**: If you get either mangled HTML or extra {::nomarkdown} tags when using this, read
|
118
|
+
[here]({{ site.baseurl }}/notes).
|
102
119
|
|
103
|
-
|
104
|
-
the `auto` output format.
|
120
|
+
- **`--alt`**
|
105
121
|
|
106
|
-
|
122
|
+
_Format:_ `--alt (alt text)`
|
107
123
|
|
108
|
-
|
124
|
+
_Example:_ `--alt Here is my alt text!`
|
109
125
|
|
110
|
-
|
126
|
+
Convenience shortcut for `--img alt="..."`
|
111
127
|
|
112
|
-
|
113
|
-
maintained: all attributes specified this way are applied to the img tag.
|
128
|
+
- **`--(element)`**
|
114
129
|
|
115
|
-
|
116
|
-
Line breaks and spaces are interchangeable, the following is perfectly acceptable:
|
130
|
+
_Format:_ `--(picture|img|source|a|parent) (Standard HTML attributes)`
|
117
131
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
img.jpg
|
122
|
-
mobile: alt.jpg
|
123
|
-
--alt Alt Text
|
124
|
-
--picture class="stumpy"
|
125
|
-
%}
|
126
|
-
```
|
127
|
-
#### Liquid variables
|
132
|
+
_Example:_ `--img class="awesome-fade-in" id="coolio" --a data-awesomeness="11"`
|
133
|
+
|
134
|
+
Apply attributes to a given HTML element. Your options are:
|
128
135
|
|
129
|
-
|
136
|
+
- `picture`
|
137
|
+
- `img`
|
138
|
+
- `source`
|
139
|
+
- `a` (anchor tag)
|
140
|
+
- `parent`
|
130
141
|
|
131
|
-
`
|
142
|
+
`--parent` will be applied to the `<picture>` if present, otherwise the `<img>`; useful when
|
143
|
+
using an `auto` output format.
|
data/jekyll_picture_tag.gemspec
CHANGED
@@ -35,11 +35,13 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_development_dependency 'rake', '~> 12.3'
|
36
36
|
spec.add_development_dependency 'rubocop'
|
37
37
|
spec.add_development_dependency 'simplecov'
|
38
|
+
spec.add_development_dependency 'solargraph'
|
38
39
|
|
39
40
|
spec.add_dependency 'addressable', '~> 2.6'
|
41
|
+
spec.add_dependency 'base32', '~> 0.3'
|
40
42
|
spec.add_dependency 'mime-types', '~> 3'
|
41
43
|
spec.add_dependency 'mini_magick', '~> 4'
|
42
|
-
spec.add_dependency 'objective_elements', '~> 1.1'
|
44
|
+
spec.add_dependency 'objective_elements', '~> 1.1.2'
|
43
45
|
|
44
46
|
spec.add_runtime_dependency 'jekyll', '< 5'
|
45
47
|
end
|
data/lib/jekyll_picture_tag.rb
CHANGED
@@ -18,9 +18,9 @@ require_relative 'jekyll_picture_tag/router'
|
|
18
18
|
#
|
19
19
|
# Description: Easy responsive images for Jekyll.
|
20
20
|
#
|
21
|
-
# Download: https://
|
22
|
-
# Documentation: https://github.
|
23
|
-
# Issues: https://github.com/rbuchberger/jekyll_picture_tag/
|
21
|
+
# Download: https://rubygems.org/gems/jekyll_picture_tag
|
22
|
+
# Documentation: https://rbuchberger.github.io/jekyll_picture_tag/
|
23
|
+
# Issues: https://github.com/rbuchberger/jekyll_picture_tag/
|
24
24
|
#
|
25
25
|
# Syntax:
|
26
26
|
# {% picture [preset] img.jpg [media_query: alt-img.jpg] [attributes] %}
|
@@ -39,30 +39,47 @@ require_relative 'jekyll_picture_tag/router'
|
|
39
39
|
#
|
40
40
|
# See the documentation for full configuration and usage instructions.
|
41
41
|
module PictureTag
|
42
|
+
# The router module is important. If you're looking for the actual code which
|
43
|
+
# handles a `PictureTag.(some method)`, start there.
|
42
44
|
extend Router
|
45
|
+
|
43
46
|
ROOT_PATH = __dir__
|
44
47
|
|
45
48
|
# This is the actual liquid tag, which provides the interface with Jekyll.
|
46
49
|
class Picture < Liquid::Tag
|
50
|
+
# First jekyll initializes our class with a few arguments, of which we only
|
51
|
+
# care about the params (arguments passed to the liquid tag). Jekyll makes
|
52
|
+
# no attempt to parse them; they're given as a string.
|
47
53
|
def initialize(tag_name, raw_params, tokens)
|
48
54
|
@raw_params = raw_params
|
49
55
|
super
|
50
56
|
end
|
51
57
|
|
58
|
+
# Then jekyll calls the 'render' method and passes it a mostly undocumented
|
59
|
+
# context object, which appears to hold the entire site including its
|
60
|
+
# configuration and the parsed _data dir.
|
52
61
|
def render(context)
|
53
|
-
|
54
|
-
|
62
|
+
setup(context)
|
63
|
+
|
64
|
+
if PictureTag.disabled?
|
65
|
+
''
|
66
|
+
else
|
67
|
+
PictureTag.output_class.new.to_s
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def setup(context)
|
55
74
|
PictureTag.context = context
|
56
75
|
|
57
|
-
#
|
76
|
+
# Now that we have both the tag parameters and the context object, we can
|
77
|
+
# build our instruction set.
|
58
78
|
PictureTag.instructions = Instructions::Set.new(@raw_params)
|
59
79
|
|
60
80
|
# We need to explicitly prevent jekyll from overwriting our generated
|
61
|
-
# files:
|
81
|
+
# image files:
|
62
82
|
Utils.keep_files
|
63
|
-
|
64
|
-
# Return a string:
|
65
|
-
PictureTag.output_class.new.to_s
|
66
83
|
end
|
67
84
|
end
|
68
85
|
end
|
@@ -1,42 +1,135 @@
|
|
1
1
|
require 'mini_magick'
|
2
|
+
require 'base32'
|
2
3
|
|
3
4
|
module PictureTag
|
4
|
-
#
|
5
|
-
# Represents a generated source file.
|
5
|
+
# Represents a generated image file.
|
6
6
|
class GeneratedImage
|
7
7
|
attr_reader :width, :format
|
8
8
|
include MiniMagick
|
9
9
|
|
10
|
-
def initialize(source_file:, width:, format:)
|
10
|
+
def initialize(source_file:, width:, format:, crop: nil, gravity: '')
|
11
11
|
@source = source_file
|
12
12
|
@width = width
|
13
13
|
@format = process_format format
|
14
|
+
@crop = crop
|
15
|
+
@gravity = gravity
|
16
|
+
end
|
14
17
|
|
15
|
-
|
18
|
+
def exists?
|
19
|
+
File.exist?(absolute_filename)
|
16
20
|
end
|
17
21
|
|
18
|
-
def
|
19
|
-
|
22
|
+
def generate
|
23
|
+
generate_image unless @source.missing || exists?
|
20
24
|
end
|
21
25
|
|
26
|
+
# /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
|
27
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
22
28
|
def absolute_filename
|
23
29
|
@absolute_filename ||= File.join(PictureTag.dest_dir, name)
|
24
30
|
end
|
25
31
|
|
32
|
+
# /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
|
33
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
34
|
+
def name
|
35
|
+
name_left + digest + name_right
|
36
|
+
end
|
37
|
+
|
38
|
+
# https://example.com/assets/images/myimage-100-123abc.jpg
|
39
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
26
40
|
def uri
|
27
41
|
ImgURI.new(name).to_s
|
28
42
|
end
|
29
43
|
|
44
|
+
def cropped_source_width
|
45
|
+
image.width
|
46
|
+
end
|
47
|
+
|
30
48
|
private
|
31
49
|
|
50
|
+
# /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
|
51
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^
|
52
|
+
def name_left
|
53
|
+
"#{@source.base_name}-#{@width}-"
|
54
|
+
end
|
55
|
+
|
56
|
+
# /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
|
57
|
+
# ^^^^^^
|
58
|
+
def digest
|
59
|
+
guess_digest if !@source.digest_guess && PictureTag.fast_build?
|
60
|
+
|
61
|
+
@source.digest
|
62
|
+
end
|
63
|
+
|
64
|
+
# /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
|
65
|
+
# ^^^^
|
66
|
+
def name_right
|
67
|
+
crop_code + '.' + @format
|
68
|
+
end
|
69
|
+
|
70
|
+
# Hash the crop settings, so we can detect when they change. We use a
|
71
|
+
# base32 encoding scheme to pack more information into fewer characters,
|
72
|
+
# without dealing with various filesystem naming limitations that would crop
|
73
|
+
# up using base64 (such as NTFS being case insensitive).
|
74
|
+
def crop_code
|
75
|
+
return '' unless @crop
|
76
|
+
|
77
|
+
Base32.encode(
|
78
|
+
Digest::MD5.hexdigest(@crop + @gravity)
|
79
|
+
)[0..2]
|
80
|
+
end
|
81
|
+
|
82
|
+
# Used for the fast build option: look for a file which matches everything
|
83
|
+
# we know about the destination file without calculating a digest on the
|
84
|
+
# source file, and if it exists we assume it's the right one.
|
85
|
+
def guess_digest
|
86
|
+
matches = dest_glob
|
87
|
+
return unless matches.length == 1
|
88
|
+
|
89
|
+
# Start and finish of the destination image's hash value
|
90
|
+
finish = -name_right.length
|
91
|
+
start = finish - 6
|
92
|
+
|
93
|
+
# The source image keeps track of this guess, so we hand it off:
|
94
|
+
@source.digest_guess = matches.first[start...finish]
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns a list of images which are probably correct.
|
98
|
+
def dest_glob
|
99
|
+
query = File.join(
|
100
|
+
PictureTag.dest_dir,
|
101
|
+
name_left + '?' * 6 + name_right
|
102
|
+
)
|
103
|
+
|
104
|
+
Dir.glob query
|
105
|
+
end
|
106
|
+
|
107
|
+
def generate_image
|
108
|
+
puts 'Generating new image file: ' + name
|
109
|
+
process_image
|
110
|
+
write_image
|
111
|
+
end
|
112
|
+
|
32
113
|
def image
|
33
|
-
@image ||=
|
114
|
+
@image ||= open_image
|
115
|
+
end
|
116
|
+
|
117
|
+
def open_image
|
118
|
+
image_base = Image.open(@source.name)
|
119
|
+
image_base.combine_options do |i|
|
120
|
+
i.auto_orient
|
121
|
+
if @crop
|
122
|
+
i.gravity @gravity
|
123
|
+
i.crop @crop
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
image_base
|
34
128
|
end
|
35
129
|
|
36
130
|
def process_image
|
37
131
|
image.combine_options do |i|
|
38
132
|
i.resize "#{@width}x"
|
39
|
-
i.auto_orient
|
40
133
|
i.strip
|
41
134
|
end
|
42
135
|
|
@@ -44,24 +137,17 @@ module PictureTag
|
|
44
137
|
image.quality PictureTag.quality(@format)
|
45
138
|
end
|
46
139
|
|
47
|
-
def generate_image
|
48
|
-
puts 'Generating new image file: ' + name
|
49
|
-
process_image
|
50
|
-
write_image
|
51
|
-
end
|
52
|
-
|
53
140
|
def write_image
|
54
|
-
|
141
|
+
# Make sure destination directory exists:
|
142
|
+
FileUtils.mkdir_p(dest_dir) unless Dir.exist?(dest_dir)
|
55
143
|
|
56
144
|
image.write absolute_filename
|
57
145
|
|
58
146
|
FileUtils.chmod(0o644, absolute_filename)
|
59
147
|
end
|
60
148
|
|
61
|
-
|
62
|
-
|
63
|
-
dir = File.dirname absolute_filename
|
64
|
-
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
|
149
|
+
def dest_dir
|
150
|
+
File.dirname absolute_filename
|
65
151
|
end
|
66
152
|
|
67
153
|
def process_format(format)
|