daily_image 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -13
- data/bin/daily_image +11 -3
- data/lib/daily_image.rb +5 -3
- data/lib/daily_image/image.rb +9 -8
- data/lib/daily_image/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c742c99232c23048b9089800c43dcfaf1837f4b79cf9f611a4ecba5d04f3843
|
4
|
+
data.tar.gz: 51bb96c6e953651f3b7a06d9177eb42959dbb8c061d3ccf8b9184e7fa21985de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cac9a0befcd6832b868c551f4ee56eac5225b32c15355e186c37078134e088a42c6bd1a6bb218f13565f15337f1a6d7744b76fda9fef5c48cd0ab0f1613fd213
|
7
|
+
data.tar.gz: 53f04fbe7ae37305a3c2f959173f953d7eeaa509b0a9cb68848788d97545f80f6ec9441bae972b8e1ff4455de04fbef6de62ac0160614ccac73ac2c9990f23bc
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# DailyImage
|
2
2
|
|
3
|
-
日签 Or
|
3
|
+
日签 Or 日历,生成一张指定日期的图片,可作为日历。Just For Fun!👏
|
4
4
|
|
5
5
|
## 使用
|
6
6
|
|
@@ -28,22 +28,22 @@ gem 'daily_image'
|
|
28
28
|
|
29
29
|
# 初始项目配置
|
30
30
|
DailyImage.configure do |config|
|
31
|
-
config
|
32
|
-
config
|
33
|
-
config
|
34
|
-
config
|
35
|
-
config
|
36
|
-
config
|
37
|
-
config
|
38
|
-
config
|
39
|
-
config
|
31
|
+
config.bg_color = [255, 255, 255] # 背景颜色
|
32
|
+
config.frame_color = [151, 158, 160] # 边框颜色
|
33
|
+
config.text_color = [100, 145, 170] # 文字颜色
|
34
|
+
config.date_color = [100, 145, 170] # 中间日期颜色
|
35
|
+
config.unused_color = [200, 205, 215] # 进度条未使用颜色
|
36
|
+
config.used_color = [100, 145, 170] # 进度条已使用颜色
|
37
|
+
config.out_frame_offset = 15 # 外层边框偏移量
|
38
|
+
config.in_frame_offset = 50 # 下半部分内层边框偏移量
|
39
|
+
config.font = 'Hiragino Sans GB' # 文字默认字体
|
40
40
|
end
|
41
41
|
|
42
42
|
# 调用方法
|
43
|
-
DailyImage.draw_image(output_path) #
|
43
|
+
DailyImage.draw_image(output_path = nil, date = Date.today) # 默认图片存放地址,包所在的目录; 默认生成为当日
|
44
44
|
|
45
45
|
# 例子
|
46
|
-
DailyImage.draw_image('./')
|
46
|
+
DailyImage.draw_image('./', '2018-09-30')
|
47
47
|
```
|
48
48
|
|
49
49
|
### 命令行
|
@@ -58,7 +58,7 @@ Specific options:
|
|
58
58
|
-b, --bg_color BG_COLOR the image's background color
|
59
59
|
-r, --frame_color FRAME_COLOR the image's frame color
|
60
60
|
-t, --text_color TEXT_COLOR the image's text color
|
61
|
-
-
|
61
|
+
-c, --date_color DATE_COLOR the middle date's text color
|
62
62
|
-n, --unused_color UNUSED_COLOR unused color of the progress bar
|
63
63
|
-u, --used_color USED_COLOR used color of the progress bar
|
64
64
|
-o OUT_FRAME_OFFSET, the outside frame offset
|
@@ -66,6 +66,7 @@ Specific options:
|
|
66
66
|
-i, --in_offset IN_FRAME_OFFSET the inside frame offset
|
67
67
|
-f, --font FONT the text font
|
68
68
|
-s, --output OUTPUT the output path, save the new image
|
69
|
+
-d, --date Specific date the date you want to generate
|
69
70
|
|
70
71
|
Common options:
|
71
72
|
-h, --help Show the help message
|
data/bin/daily_image
CHANGED
@@ -17,7 +17,8 @@ class DailyImageOptparser
|
|
17
17
|
:font,
|
18
18
|
:out_frame_offset,
|
19
19
|
:in_frame_offset,
|
20
|
-
:output_path
|
20
|
+
:output_path,
|
21
|
+
:date
|
21
22
|
|
22
23
|
def initialize
|
23
24
|
end
|
@@ -37,6 +38,7 @@ class DailyImageOptparser
|
|
37
38
|
in_frame_offset_option(parser)
|
38
39
|
font_option(parser)
|
39
40
|
output_path_option(parser)
|
41
|
+
date_option(parser)
|
40
42
|
|
41
43
|
parser.separator ""
|
42
44
|
parser.separator "Common options:"
|
@@ -73,7 +75,7 @@ class DailyImageOptparser
|
|
73
75
|
end
|
74
76
|
|
75
77
|
def date_color_option(parser)
|
76
|
-
parser.on("-
|
78
|
+
parser.on("-c", "--date_color DATE_COLOR", "the middle date's text color") do |date_color|
|
77
79
|
self.date_color = date_color
|
78
80
|
end
|
79
81
|
end
|
@@ -114,6 +116,12 @@ class DailyImageOptparser
|
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
119
|
+
def date_option(parser)
|
120
|
+
parser.on("-d", "--date Specific date", "the date you want to generate") do |date|
|
121
|
+
self.date = Date.parse(date.to_s) rescue Date.today
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
117
125
|
end
|
118
126
|
|
119
127
|
attr_reader :parser, :options
|
@@ -142,4 +150,4 @@ DailyImage.configure do |config|
|
|
142
150
|
config.font = options.font if options.font
|
143
151
|
end
|
144
152
|
|
145
|
-
DailyImage.draw_image(options.output_path)
|
153
|
+
DailyImage.draw_image(options.output_path, options.date)
|
data/lib/daily_image.rb
CHANGED
@@ -17,11 +17,13 @@ module DailyImage
|
|
17
17
|
DailyImage::Config.instance.configuration
|
18
18
|
end
|
19
19
|
|
20
|
-
def draw_image(output_path = nil)
|
20
|
+
def draw_image(output_path = nil, date = Date.today)
|
21
21
|
output_path ||= Dir.pwd
|
22
|
-
|
22
|
+
date = Date.parse(date.to_s) rescue Date.today
|
23
23
|
|
24
|
-
|
24
|
+
output_file = File.join(output_path, "daily_#{date}.jpeg")
|
25
|
+
|
26
|
+
image = DailyImage::Image.new(date: date).draw_image
|
25
27
|
|
26
28
|
image.write_to_file(output_file, Q: 100)
|
27
29
|
end
|
data/lib/daily_image/image.rb
CHANGED
@@ -2,9 +2,10 @@
|
|
2
2
|
module DailyImage
|
3
3
|
class Image
|
4
4
|
|
5
|
-
def initialize(width = 600, height = 800)
|
5
|
+
def initialize(width = 600, height = 800, date: Date.today)
|
6
6
|
@width = width
|
7
7
|
@height = height
|
8
|
+
@date = date
|
8
9
|
end
|
9
10
|
|
10
11
|
def draw_image
|
@@ -60,7 +61,7 @@ module DailyImage
|
|
60
61
|
|
61
62
|
# 画出中间日期
|
62
63
|
def draw_day(image)
|
63
|
-
day =
|
64
|
+
day = @date.day.to_s
|
64
65
|
|
65
66
|
# 生成字体图片
|
66
67
|
text = generate_text_image(day, dpi: 1000, text_color: config[:date_color])
|
@@ -74,7 +75,7 @@ module DailyImage
|
|
74
75
|
|
75
76
|
# 画出左上角日期
|
76
77
|
def draw_date(image)
|
77
|
-
date =
|
78
|
+
date = @date.to_s
|
78
79
|
text = generate_text_image(date, dpi: 150)
|
79
80
|
|
80
81
|
# 计算放置位置
|
@@ -86,8 +87,8 @@ module DailyImage
|
|
86
87
|
|
87
88
|
# 画出右上角信息
|
88
89
|
def draw_week(image)
|
89
|
-
week_arr = ['
|
90
|
-
week = week_arr[
|
90
|
+
week_arr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
|
91
|
+
week = week_arr[@date.cwday - 1]
|
91
92
|
|
92
93
|
text = generate_text_image(week, dpi: 140)
|
93
94
|
|
@@ -100,7 +101,7 @@ module DailyImage
|
|
100
101
|
|
101
102
|
# 画出进度描述信息
|
102
103
|
def draw_progress_txt(image)
|
103
|
-
day =
|
104
|
+
day = @date.yday
|
104
105
|
percent = (percent_of_year * 100).round(2)
|
105
106
|
text = "第 #{day} 天,进度已消耗 #{percent}%"
|
106
107
|
|
@@ -182,8 +183,8 @@ module DailyImage
|
|
182
183
|
|
183
184
|
# 计算当天时间在一年的百分比
|
184
185
|
def percent_of_year
|
185
|
-
days = Date.new(
|
186
|
-
current_days =
|
186
|
+
days = Date.new(@date.year, 12, 31).yday
|
187
|
+
current_days = @date.yday
|
187
188
|
|
188
189
|
(current_days.to_f / days).round(4)
|
189
190
|
end
|
data/lib/daily_image/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daily_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- renyijiu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|