-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrakefile.rb
More file actions
110 lines (87 loc) · 3.11 KB
/
rakefile.rb
File metadata and controls
110 lines (87 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require 'jekyll'
require 'rake-jekyll'
require 'blurhash'
require 'rmagick'
require 'image_processing/mini_magick'
require 'base64'
desc "Convert images to text files"
task :project_imgs_to_txt do
extensions = ['.jpg', '.png', '.gif', 'webp']
Dir.each_child('_projects') do |project|
next if project == '.DS_Store'
next unless project == 'ellevate.md'
# next unless project == 'bemo.md'
folder = File.basename(project, '.md')
puts "Creating base64 images for #{project}..."
Dir.foreach('./_images/' + folder + '/') do |file|
next unless file
extension = File.extname(file)
# check that its an img
next unless extensions.include?(extension)
name = File.basename(file, extension)
name_array = name.to_s.split('.')
next if name_array.include?('low')
temp_name = name + '.txt.jpg'
Dir.mkdir('./_includes/projects/' + folder) unless Dir.exists?('./_includes/projects/' + folder)
temp = File.path('./tmp/' + name + extension)
input = File.path('./_images/' + folder + '/' + file)
output = './_includes/projects/' + folder + '/' + name + '.txt'
w = name_array[1].to_i
h = name_array[2].to_i
magick = ImageProcessing::MiniMagick
.source(input)
.resize_to_limit(w/90,h/90)
.convert('JPG:- | base64')
.call(save: false)
magick << temp
magick.call
magick = ImageProcessing::MiniMagick
.source(temp)
.resize_to_limit(w,h)
.convert('JPG:- | base64')
.call
`bash image2urijpeg.sh #{temp} > #{output}`
end
end
end
desc "Add dimensions to file name"
task :rename_project_images do
extensions = ['.png']
Dir.each_child('_projects') do |project|
next if project == '.DS_Store'
next unless project == 'ellevate.md'
folder = File.basename(project, '.md')
puts "Adding image dimensions for #{project}..."
Dir.foreach('./_images/' + folder + '/') do |file|
next unless file
extension = File.extname(file)
next unless extensions.include?(extension)
name = File.basename(file, extension)
name_array = name.to_s.split('.')
input = File.path('./_images/' + folder + '/' + file)
dimensions = MiniMagick::Image.new(input).dimensions
File.rename(input, "./_images/#{folder}/#{name_array.first}.#{dimensions[0]}.#{dimensions[1]}#{extension}" )
end
end
end
desc "Convert images to webp"
task :convert_to_webp do
extensions = ['.png']
Dir.each_child('_projects') do |project|
next if project == '.DS_Store'
next unless project == 'ellevate.md'
folder = File.basename(project, '.md')
puts "Convertring to webp for #{project}..."
Dir.foreach('./_images/' + folder + '/') do |file|
input = File.path('./_images/' + folder + '/' + file)
next unless file
extension = File.extname(file)
next unless extensions.include?(extension)
extension = File.extname(file)
name = File.basename(file, extension)
image = MiniMagick::Image.open(input)
image.format "webp"
image.write "./_images/#{folder}/#{name}.webp"
end
end
end