jekyll-pig 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-pig.rb +59 -26
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f73810e7360f4a48d45c78d83f0653beb16da0243cfb94164a6cc049a16cbe70
4
- data.tar.gz: cd92492bd2faa8766fe3b9afbed32b295cbe9deb828e30422eff3da8055fe76d
3
+ metadata.gz: bd6c955e443343e3d518c3b174cb1f7dc665f810c8420f5dec7c8dfccf345f2d
4
+ data.tar.gz: 3d3c91f6ca57ecbd9acee9dd68554f7eb8ce04500008c9fb09c827f9f2cd88c4
5
5
  SHA512:
6
- metadata.gz: 342632257774fca9636fabfe4dc78866f5643075426b7c3fff2b88ffb55ca58b2f72172d98c7eb82d8e0f0b309f8cb4eac87878c7160c2b7c643dee343934ffa
7
- data.tar.gz: 227ba484c11be61757766ada3c307ed79cc3333d7d6056ba31282610d308063f2cd7958af00933fbd52bee92a1b0411dbeb4c8c007dd65823545e6a2a6d25b29
6
+ metadata.gz: d2ab7eb1ef1d385abb3f274659435f844e0db139822da055e429e449fea15b64145c5f3082be02fb13a9b1bad2c27ef7665a965173f0e839ed2c6e7fed40bd18
7
+ data.tar.gz: 5b3cb6c3c98675efe89e9f31a65b59765f66768ac4ffa51318b90ad93d5d179f45710ddf890063da9c90d798164f80274593ec6dc686fcf1a742e1742baa5de0
@@ -76,10 +76,10 @@ module JekyllPig
76
76
  image_data
77
77
  end
78
78
 
79
- #read images that require processing from gallery
80
- def get_images(gallery_path)
81
- patterns = ['*.jpg', '*.jpeg', '*.png'].map { |ext| File.join(gallery_path, ext) }
82
- Dir.glob(patterns).map { |path| File.basename(path) }
79
+ #get a list of image file names from a given path
80
+ def get_images(path)
81
+ patterns = ['*.jpg', '*.jpeg', '*.png'].map { |ext| File.join(path, ext) }
82
+ Dir.glob(patterns).map { |filepath| File.basename(filepath) }
83
83
  end
84
84
 
85
85
  def get_image(gallery_path, image_name)
@@ -128,20 +128,48 @@ module JekyllPig
128
128
  image_html_url(gallery_name, image_data[index]['filename'])
129
129
  end
130
130
 
131
- #create thumbnails and fullsize image assets, and create full size html page for a given image
132
- def process_image(image_data, gallery_id, gallery_path, image_name)
133
- #puts "jekyll-pig: processing " << image_name
131
+ #create thumbnails and fullsize image assets
132
+ def process_images(image_data, gallery_id, gallery_path, images)
134
133
  #create thumbs
135
- [1024, 500, 250, 100, 20].each { |size|
134
+ sizes = [1024, 500, 250, 100, 20]
135
+ sizes.each { |size|
136
+ #output path for current size
136
137
  size_out_path = File.join(@img_path, gallery_id, size.to_s)
137
- resized_img_path = File.join(size_out_path, image_name)
138
- if not File.exists? resized_img_path
139
- image = get_image(gallery_path, image_name)
140
- image.resize("x" + size.to_s)
141
- FileUtils.mkdir_p size_out_path unless File.exists? size_out_path
142
- image.write(resized_img_path)
143
- end
138
+ FileUtils.mkdir_p size_out_path unless File.exists? size_out_path
139
+
140
+ #images that have already been processed for the current size
141
+ done_images = get_images(size_out_path)
142
+ #all images in the gallery with the ones already done taken away
143
+ todo_images = images - done_images
144
+
145
+ #function to get the source path to use for creating the given size thumbnail
146
+ #i.e. use the 500px sized images to make the 250px versions
147
+ source_for_size = -> (size) {
148
+ index = sizes.index(size)
149
+ source = gallery_path
150
+ if index != nil && index != 0
151
+ source = File.join(@img_path, gallery_id, sizes[index - 1].to_s)
152
+ end
153
+ source
154
+ }
155
+
156
+ #do the processing in a batch
157
+ mog = MiniMagick::Tool::Mogrify.new
158
+ mog.resize("x#{size}")
159
+ mog.sampling_factor('4:2:0')
160
+ mog.colorspace('RGB')
161
+ mog.interlace('Plane')
162
+ mog.strip()
163
+ mog.quality('75')
164
+ mog.path(size_out_path)
165
+ source_path = source_for_size.call(size)
166
+ todo_images.each { |todo| mog << File.join(source_path, todo) }
167
+ mog.call
144
168
  }
169
+ end
170
+
171
+ #create full size html page for a given image
172
+ def process_image(image_data, gallery_id, gallery_path, image_name)
145
173
  full_size_html_path = File.join(@html_path, gallery_id, image_name + ".html")
146
174
  #create full size html if it doesn't exist
147
175
  if not File.exists? full_size_html_path
@@ -231,6 +259,7 @@ module JekyllPig
231
259
 
232
260
  #get image data from _data
233
261
  image_data = get_image_data(gallery.name)
262
+ old_image_data = image_data.clone
234
263
 
235
264
  #get images from gallery
236
265
  images = get_images(gallery.path)
@@ -241,21 +270,25 @@ module JekyllPig
241
270
  #sort image data
242
271
  image_data = image_data.sort_by { |data| data['datetime'] }
243
272
 
244
- #process images
273
+ #create thumbs
274
+ process_images(image_data, gallery.name, gallery.path, images)
275
+
245
276
  images.each do |image_name|
246
- #create thumbs, full size, and html assets for each image
277
+ #create html assets for each image
247
278
  process_image(image_data, gallery.name, gallery.path, image_name)
248
279
  end
249
280
 
250
- #write image_data
251
- File.open(File.join(@data_path, "#{gallery.name}.json"), 'w') { |file|
252
- file.write(image_data.to_json)
253
- }
254
-
255
- #save this gallery's includable content
256
- File.open(File.join(@includes_path, "#{gallery.name}.html"), 'w') { |file|
257
- file.write(gallery_html(gallery.name, image_data))
258
- }
281
+ if image_data != old_image_data
282
+ #write image_data
283
+ File.open(File.join(@data_path, "#{gallery.name}.json"), 'w') { |file|
284
+ file.write(image_data.to_json)
285
+ }
286
+
287
+ #save this gallery's includable content
288
+ File.open(File.join(@includes_path, "#{gallery.name}.html"), 'w') { |file|
289
+ file.write(gallery_html(gallery.name, image_data))
290
+ }
291
+ end
259
292
  end
260
293
  end
261
294
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-pig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Holzman