jekyll_picture_tag 1.10.2 → 2.0.0pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +4 -0
  3. data/.github/workflows/code-checks.yml +33 -0
  4. data/.gitignore +3 -0
  5. data/.rubocop.yml +32 -0
  6. data/.ruby-version +1 -1
  7. data/docs/.envrc +2 -0
  8. data/docs/Gemfile +4 -2
  9. data/docs/Gemfile.lock +14 -12
  10. data/docs/_config.yml +6 -10
  11. data/docs/devs/contributing/code.md +54 -0
  12. data/docs/devs/contributing/docs.md +31 -0
  13. data/docs/devs/contributing/index.md +15 -0
  14. data/docs/devs/contributing/setup.md +33 -0
  15. data/docs/devs/contributing/testing.md +23 -0
  16. data/docs/devs/index.md +7 -0
  17. data/docs/devs/releases.md +113 -0
  18. data/docs/index.md +62 -31
  19. data/docs/logo.png +0 -0
  20. data/docs/logo.svg +880 -0
  21. data/docs/users/configuration/directories.md +34 -0
  22. data/docs/users/configuration/disable.md +24 -0
  23. data/docs/users/configuration/fast_build.md +28 -0
  24. data/docs/users/configuration/ignore_missing.md +23 -0
  25. data/docs/users/configuration/index.md +29 -0
  26. data/docs/users/configuration/kramdown_fix.md +20 -0
  27. data/docs/users/configuration/suppress_warnings.md +16 -0
  28. data/docs/users/configuration/urls.md +69 -0
  29. data/docs/users/getting_started.md +55 -0
  30. data/docs/users/index.md +7 -0
  31. data/docs/users/installation.md +31 -0
  32. data/docs/users/liquid_tag/argument_reference/alternate_images.md +18 -0
  33. data/docs/users/liquid_tag/argument_reference/attributes.md +42 -0
  34. data/docs/users/liquid_tag/argument_reference/base_image.md +12 -0
  35. data/docs/users/liquid_tag/argument_reference/crop.md +33 -0
  36. data/docs/users/liquid_tag/argument_reference/link.md +16 -0
  37. data/docs/users/liquid_tag/argument_reference/preset.md +17 -0
  38. data/docs/users/liquid_tag/argument_reference/readme.md +9 -0
  39. data/docs/users/liquid_tag/examples.md +81 -0
  40. data/docs/users/liquid_tag/index.md +31 -0
  41. data/docs/users/notes/git_lfs.md +7 -0
  42. data/docs/users/notes/github_pages.md +5 -0
  43. data/docs/users/notes/html_attributes.md +5 -0
  44. data/docs/users/notes/index.md +6 -0
  45. data/docs/users/notes/kramdown_bug.md +41 -0
  46. data/docs/users/notes/managing_images.md +21 -0
  47. data/docs/{migration.md → users/notes/migration_1.md} +1 -1
  48. data/docs/users/notes/migration_2.md +99 -0
  49. data/docs/users/presets/cropping.md +60 -0
  50. data/docs/users/presets/default.md +32 -0
  51. data/docs/users/presets/examples.md +111 -0
  52. data/docs/users/presets/fallback_image.md +28 -0
  53. data/docs/users/presets/html_attributes.md +26 -0
  54. data/docs/users/presets/image_formats.md +21 -0
  55. data/docs/users/presets/image_quality.md +120 -0
  56. data/docs/users/presets/index.md +137 -0
  57. data/docs/users/presets/link_source.md +16 -0
  58. data/docs/users/presets/markup_formats/fragments.md +48 -0
  59. data/docs/users/presets/markup_formats/javascript_friendly.md +57 -0
  60. data/docs/users/presets/markup_formats/readme.md +43 -0
  61. data/docs/users/presets/markup_formats/standard_html.md +25 -0
  62. data/docs/users/presets/media_queries.md +36 -0
  63. data/docs/users/presets/nomarkdown_override.md +17 -0
  64. data/docs/users/presets/pixel_ratio_srcsets.md +32 -0
  65. data/docs/users/presets/quality_width_graph.png +0 -0
  66. data/docs/users/presets/width_height_attributes.md +34 -0
  67. data/docs/users/presets/width_srcsets.md +123 -0
  68. data/docs/users/tutorial.md +97 -0
  69. data/jekyll_picture_tag.gemspec +38 -24
  70. data/lib/jekyll_picture_tag.rb +11 -9
  71. data/lib/jekyll_picture_tag/cache.rb +64 -0
  72. data/lib/jekyll_picture_tag/defaults/global.rb +18 -0
  73. data/lib/jekyll_picture_tag/defaults/presets.rb +57 -0
  74. data/lib/jekyll_picture_tag/images.rb +4 -0
  75. data/lib/jekyll_picture_tag/images/generated_image.rb +92 -0
  76. data/lib/jekyll_picture_tag/images/image_file.rb +90 -0
  77. data/lib/jekyll_picture_tag/{img_uri.rb → images/img_uri.rb} +4 -10
  78. data/lib/jekyll_picture_tag/images/source_image.rb +138 -0
  79. data/lib/jekyll_picture_tag/instructions.rb +70 -6
  80. data/lib/jekyll_picture_tag/instructions/children/config.rb +128 -0
  81. data/lib/jekyll_picture_tag/instructions/children/context.rb +24 -0
  82. data/lib/jekyll_picture_tag/instructions/children/params.rb +90 -0
  83. data/lib/jekyll_picture_tag/instructions/children/parsers.rb +41 -0
  84. data/lib/jekyll_picture_tag/instructions/children/preset.rb +182 -0
  85. data/lib/jekyll_picture_tag/instructions/parents/conditional_instruction.rb +69 -0
  86. data/lib/jekyll_picture_tag/instructions/parents/env_instruction.rb +29 -0
  87. data/lib/jekyll_picture_tag/output_formats/basic.rb +11 -21
  88. data/lib/jekyll_picture_tag/output_formats/img.rb +11 -0
  89. data/lib/jekyll_picture_tag/output_formats/picture.rb +22 -0
  90. data/lib/jekyll_picture_tag/parsers.rb +5 -0
  91. data/lib/jekyll_picture_tag/{instructions → parsers}/arg_splitter.rb +4 -3
  92. data/lib/jekyll_picture_tag/parsers/configuration.rb +28 -0
  93. data/lib/jekyll_picture_tag/{instructions → parsers}/html_attributes.rb +1 -1
  94. data/lib/jekyll_picture_tag/parsers/preset.rb +43 -0
  95. data/lib/jekyll_picture_tag/{instructions → parsers}/tag_parser.rb +15 -12
  96. data/lib/jekyll_picture_tag/router.rb +35 -92
  97. data/lib/jekyll_picture_tag/srcsets/basic.rb +11 -8
  98. data/lib/jekyll_picture_tag/utils.rb +24 -20
  99. data/lib/jekyll_picture_tag/version.rb +1 -1
  100. data/readme.md +15 -12
  101. metadata +206 -95
  102. data/.travis.yml +0 -8
  103. data/Dockerfile +0 -9
  104. data/docs/_layouts/directory.html +0 -32
  105. data/docs/assets/style.css +0 -31
  106. data/docs/contributing.md +0 -109
  107. data/docs/example_presets.md +0 -116
  108. data/docs/global_configuration.md +0 -173
  109. data/docs/installation.md +0 -45
  110. data/docs/notes.md +0 -91
  111. data/docs/output.md +0 -63
  112. data/docs/presets.md +0 -361
  113. data/docs/releases.md +0 -65
  114. data/docs/usage.md +0 -143
  115. data/jekyll-picture-tag.gemspec +0 -52
  116. data/lib/jekyll-picture-tag.rb +0 -25
  117. data/lib/jekyll_picture_tag/defaults/global.yml +0 -11
  118. data/lib/jekyll_picture_tag/defaults/presets.yml +0 -10
  119. data/lib/jekyll_picture_tag/generated_image.rb +0 -161
  120. data/lib/jekyll_picture_tag/instructions/configuration.rb +0 -121
  121. data/lib/jekyll_picture_tag/instructions/preset.rb +0 -102
  122. data/lib/jekyll_picture_tag/instructions/set.rb +0 -71
  123. data/lib/jekyll_picture_tag/source_image.rb +0 -87
data/docs/releases.md DELETED
@@ -1,65 +0,0 @@
1
- ---
2
- ---
3
- # Release History
4
- * 1.10.2 July 6, 2020
5
- * Bugfix for fallback image files not actually getting generated
6
- * 1.10.1 July 2, 2020
7
- * Bugfix for erroneously regenerated images
8
- * 1.10.0 May 11, 2020
9
- * **Image Cropping support!** access the power of ImageMagick's `crop` function.
10
- * Don't issue a warning when `default` preset is not found.
11
- * Documentation improvements
12
- * 1.9.0 Feb 2, 2020
13
- * Add `fast_build` global setting
14
- * Add `disabled` global setting
15
- * Reduce unnecessary disk IO; sites with many source images should see build times improve when
16
- no new images need to be generated.
17
- * Add support for empty attributes; specifically so best-practice for decorative images (`alt=""`)
18
- is possible.
19
- * 1.8.0 Nov 25, 2019
20
- * Add `data_sizes` setting for the `data_` family of output formats.
21
- * 1.7.1 Nov 14, 2019
22
- * Fix some HTML attribute related bugs
23
- * Add a few items to the FAQ
24
- * 1.7.0 Aug 12, 2019
25
- * Add support for setting generated image quality, either generally or specific to given
26
- formats.
27
- * Add support for spaces and other url-encoded characters in filenames
28
- * Documentation restructure - Moved it out of the wiki, into the `docs` folder.
29
- * Bugfix: Fallback image width will now be checked against source image width.
30
- * Bugfix: Minor fix to nomarkdown wrapper output
31
- * link_source will now target the base source image, rather than finding the biggest one.
32
- * Remove fastimage dependency, add addressable dependency.
33
- * Moderately significant refactoring and code cleanup
34
- * Decent set of tests added
35
- * 1.6.0 Jul 2, 2019:
36
- * Missing Preset warning respects `data_dir` setting
37
- * Add `continue_on_missing` option
38
- * 1.5.0 Jun 26, 2019:
39
- * better `{::nomarkdown}` necessity detection
40
- * allow user to override `{::nomarkdown}` autodetection
41
- * 1.4.0 Jun 26, 2019:
42
- * Rename gem from `jekyll-picture-tag` to `jekyll_picture_tag`, allowing us to use rubygems again.
43
- * Add new output format: `naked_srcset`.
44
- * 1.3.1 Jun 21, 2019: Bugfix
45
- * 1.3.0 Jun 7, 2019:
46
- * Initial compatibility with Jekyll 4.0
47
- * bugfixes
48
- * change to generated image naming-- The first build after this update will be longer, and you
49
- might want to clear out your generated images.
50
- * 1.2.0 Feb 9, 2019:
51
- * Add nomarkdown fix
52
- * noscript option
53
- * relative url option
54
- * anchor tag wrappers
55
- * 1.1.0 Jan 22, 2019:
56
- * Add direct_url markup format,
57
- * auto-orient images before stripping metadata
58
- * 1.0.2 Jan 18, 2019: Fix ruby version specification
59
- * 1.0.1 Jan 13, 2019: Added ruby version checking
60
- * **1.0.0** Nov 27, 2018: Rewrite from the ground up. See the [migration guide]({{ site.baseurl }}/migration).
61
- * 0.2.2 Aug 2, 2013: Bugfixes
62
- * 0.2.1 Jul 17, 2013: Refactor again, add Liquid parsing.
63
- * 0.2.0 Jul 14, 2013: Rewrite code base, bring in line with Jekyll Image Tag.
64
- * 0.1.1 Jul 5, 2013: Quick round of code improvements.
65
- * 0.1.0 Jul 5, 2013: Initial release.
data/docs/usage.md DELETED
@@ -1,143 +0,0 @@
1
- ---
2
- ---
3
-
4
- # How to use the Liquid Tag:
5
-
6
- ## Format:
7
-
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.
14
-
15
- ## Examples:
16
-
17
- {% raw %}
18
- `{% picture example.jpg %}`
19
-
20
- `{% picture thumbnail example.jpg 1:1 --alt Example Image %}`
21
-
22
- `{% picture example.jpg 16:9 north --picture class="attribute-demo" %}`
23
-
24
- `{% picture blog_index {{ post.image }} --link {{ post.url }} %}`
25
-
26
- `{% picture "some example.jpg" mobile: other\ example.jpg %}`
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"
36
- --link /
37
- %}
38
- ```
39
-
40
- {% endraw %}
41
-
42
- ## Argument reference
43
-
44
- Given in order:
45
-
46
- - **Preset**
47
-
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.
51
-
52
- - **Base Image** (Required)
53
-
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.
56
-
57
- For filenames with spaces, either use double quotes (`"my image.jpg"`) or a backslash (`my\ image.jpg`).
58
-
59
- - **Crop**
60
-
61
- **Check the [ installation guide ](installation) before using this feature.**
62
-
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.
69
-
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.
74
-
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.
80
-
81
- For detailed documentation, see ImageMagick's
82
- [crop](http://www.imagemagick.org/script/command-line-options.php#crop) tool.
83
-
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.
87
-
88
- - **Alternate images**
89
-
90
- _Format:_ `(media query preset): (filename) (...)`
91
-
92
- _Example:_ `tablet: img_cropped.jpg mobile: img_cropped_more.jpg`
93
-
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.
98
-
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.
102
-
103
- - **Attributes**
104
-
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.
107
-
108
- - **`--link`**
109
-
110
- _Format:_ `--link (some url)`
111
-
112
- _Examples_: `--link https://example.com`, `--link /blog/some_post/`
113
-
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.
116
-
117
- **Note**: If you get either mangled HTML or extra {::nomarkdown} tags when using this, read
118
- [here]({{ site.baseurl }}/notes).
119
-
120
- - **`--alt`**
121
-
122
- _Format:_ `--alt (alt text)`
123
-
124
- _Example:_ `--alt Here is my alt text!`
125
-
126
- Convenience shortcut for `--img alt="..."`
127
-
128
- - **`--(element)`**
129
-
130
- _Format:_ `--(picture|img|source|a|parent) (Standard HTML attributes)`
131
-
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:
135
-
136
- - `picture`
137
- - `img`
138
- - `source`
139
- - `a` (anchor tag)
140
- - `parent`
141
-
142
- `--parent` will be applied to the `<picture>` if present, otherwise the `<img>`; useful when
143
- using an `auto` output format.
@@ -1,52 +0,0 @@
1
- # Why 2 gemspecs?
2
- #
3
- # Originally, this gem was named 'jekyll-picture-tag', and published on rubygems
4
- # under this name. There was a break in development, during which push access to
5
- # rubygems was lost. Development was later resumed, and as a workaround for that
6
- # issue the installation instructions were to source the gem from the Github
7
- # repository.
8
- #
9
- # Ultimately, the decision was made to rename it by switching the dashes for
10
- # underscores, which follows best practice and allows pushing it to rubygems
11
- # under the new name. The drawback of this situation is that everyone who
12
- # followed the installaion instructions previously would see their site
13
- # inexplicably break, as it would be searching for a gemspec that doesn't exist.
14
- # As a workaround (to the old workaround... sigh) this gemspec lets us print a
15
- # warning and then require the new version, which keeps old sites working while
16
- # encouraging people to use rubygems.
17
-
18
- lib = File.expand_path('lib', __dir__)
19
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
20
- require 'jekyll_picture_tag/version'
21
-
22
- Gem::Specification.new do |spec|
23
- spec.name = 'jekyll-picture-tag'
24
- spec.version = PictureTag::VERSION
25
- spec.authors = ['Robert Wierzbowski', 'Brendan Tobolaski',
26
- 'Robert Buchberger']
27
- spec.email = ['robert@buchberger.cc']
28
-
29
- spec.summary = 'Easy responsive images for Jekyll.'
30
- spec.description = <<~HEREDOC
31
- ____ _ _
32
- | _ \ ___ _ __ _ __ ___ ___ __ _| |_ ___ __| |
33
- | | | |/ _ \ '_ \| '__/ _ \/ __/ _` | __/ _ \/ _` |
34
- | |_| | __/ |_) | | | __/ (_| (_| | || __/ (_| |
35
- |____/ \___| .__/|_| \___|\___\__,_|\__\___|\__,_|
36
- |_|
37
-
38
- This gem has been renamed! Use jekyll_picture_tag instead, which is now
39
- hosted on rubygems.
40
- HEREDOC
41
- spec.homepage = 'https://github.com/rbuchberger/jekyll_picture_tag'
42
- spec.license = 'BSD-3-Clause'
43
- spec.require_paths = ['lib']
44
-
45
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
46
- f.match(%r{^(test|spec|features)/})
47
- end
48
-
49
- spec.required_ruby_version = ['>= 2.5', '< 3']
50
-
51
- spec.add_dependency 'jekyll_picture_tag'
52
- end
@@ -1,25 +0,0 @@
1
- # rubocop:disable Naming/FileName
2
- puts '-' * 80
3
- # rubocop:enable Naming/FileName
4
-
5
- puts <<~HEREDOC
6
- \033[31;1;4m
7
- Important message from Jekyll Picture Tag:
8
- \033[0m
9
- Good news! We're back up on rubygems.
10
- Bad news. You need to update your Gemfile. Remove the following line:
11
-
12
- gem 'jekyll-picture-tag', git: 'https://github.com/robwierzbowski/jekyll-picture-tag/'
13
-
14
- and replace it with something like:
15
-
16
- gem 'jekyll_picture_tag', '~> 1.6'
17
-
18
- Sorry about that. For an explanation, see issue #120:
19
- https://github.com/rbuchberger/jekyll-picture-tag/issues/120
20
-
21
- HEREDOC
22
-
23
- puts '-' * 80
24
-
25
- require 'jekyll_picture_tag'
@@ -1,11 +0,0 @@
1
- # Default settings for _config.yml
2
- picture:
3
- source: ''
4
- output: generated
5
- suppress_warnings: false
6
- relative_url: true
7
- cdn_environments: ['production']
8
- nomarkdown: true
9
- ignore_missing_images: false
10
- disabled: false
11
- fast_build: false
@@ -1,10 +0,0 @@
1
- markup: auto
2
- formats: [original]
3
- widths: [400, 600, 800, 1000]
4
- fallback_width: 800
5
- fallback_format: original
6
- noscript: false
7
- link_source: false
8
- quality: 75
9
- data_sizes: true
10
- gravity: center
@@ -1,161 +0,0 @@
1
- require 'mini_magick'
2
- require 'base32'
3
-
4
- module PictureTag
5
- # Represents a generated image file.
6
- class GeneratedImage
7
- attr_reader :width, :format
8
- include MiniMagick
9
-
10
- def initialize(source_file:, width:, format:, crop: nil, gravity: '')
11
- @source = source_file
12
- @width = width
13
- @format = process_format format
14
- @crop = crop
15
- @gravity = gravity
16
- end
17
-
18
- def exists?
19
- File.exist?(absolute_filename)
20
- end
21
-
22
- def generate
23
- generate_image unless @source.missing || exists?
24
- end
25
-
26
- # /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
27
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28
- def absolute_filename
29
- @absolute_filename ||= File.join(PictureTag.dest_dir, name)
30
- end
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
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40
- def uri
41
- ImgURI.new(name).to_s
42
- end
43
-
44
- def cropped_source_width
45
- image.width
46
- end
47
-
48
- private
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
-
113
- def 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
128
- end
129
-
130
- def process_image
131
- image.combine_options do |i|
132
- i.resize "#{@width}x"
133
- i.strip
134
- end
135
-
136
- image.format @format
137
- image.quality PictureTag.quality(@format)
138
- end
139
-
140
- def write_image
141
- # Make sure destination directory exists:
142
- FileUtils.mkdir_p(dest_dir) unless Dir.exist?(dest_dir)
143
-
144
- image.write absolute_filename
145
-
146
- FileUtils.chmod(0o644, absolute_filename)
147
- end
148
-
149
- def dest_dir
150
- File.dirname absolute_filename
151
- end
152
-
153
- def process_format(format)
154
- if format.casecmp('original').zero?
155
- @source.ext
156
- else
157
- format.downcase
158
- end
159
- end
160
- end
161
- end