daily_image 0.1.0 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1efdea98fc3b59bc85431e1c8384ce8d0095cc22ff54d11021ef6918df677ae3
4
- data.tar.gz: 804765d2e0540898e7853407fb3a23bcd7cd51128b8d30e57cd5f24a8daed6f8
3
+ metadata.gz: d230c52cf5a8cc4deef5b16da4df59c39732d7936d439131cfe112846c110f69
4
+ data.tar.gz: 265accdddf005fac351582fffb8d083717253b57b16993e338d8d7c68d8221b8
5
5
  SHA512:
6
- metadata.gz: 34ba4f064cb456f6747f40fb7355e5e8922612736ef322d3fa129911b4289144eee46df4b7185746f5bcb248ed260ed3c14d61189722e90c2ab27ea59333d461
7
- data.tar.gz: 219c852823562df7adb6f7b59efb75c773fe030afeb4e6b1825db5227eafc6df0133e113902adc8975e15225975305f2a46cbdff0a27b3af11ebcffb6366cdda
6
+ metadata.gz: 4dd49bb2b012b4e80c740800206d35f91a25e989cf33b383a98f7d303d83c954a87b516a6b0ec8775be9ff88ee3a43fc6651f6d09a5a4d76ba93bbad39bd6373
7
+ data.tar.gz: 00de691cb6076590e59dfcdbcc81bfe6b9700d4241cf010c9ab7f89f5bf44f5e309dd06c0a12eaa7c9cf057f1c038ecf35286f47b334293315516d23e1428821
data/.gitignore CHANGED
@@ -6,4 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /.idea/
9
- /.DS_Store
9
+ /.DS_Store
10
+ Gemfile.lock
@@ -0,0 +1 @@
1
+ 2.6.4
data/Gemfile CHANGED
@@ -2,7 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
- gem 'ruby-vips', '~> 2.0.13'
6
-
7
5
  # Specify your gem's dependencies in daily_image.gemspec
8
6
  gemspec
@@ -1,15 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- daily_image (0.1.0)
4
+ daily_image (0.1.5)
5
+ ruby-vips (~> 2.0.17)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
- ffi (1.9.25)
10
+ ffi (1.11.1)
10
11
  minitest (5.11.3)
11
- rake (10.5.0)
12
- ruby-vips (2.0.13)
12
+ rake (12.3.3)
13
+ ruby-vips (2.0.17)
13
14
  ffi (~> 1.9)
14
15
 
15
16
  PLATFORMS
@@ -19,8 +20,7 @@ DEPENDENCIES
19
20
  bundler (~> 1.16)
20
21
  daily_image!
21
22
  minitest (~> 5.0)
22
- rake (~> 10.0)
23
- ruby-vips (~> 2.0.13)
23
+ rake (~> 12.3, >= 12.3.3)
24
24
 
25
25
  BUNDLED WITH
26
- 1.16.1
26
+ 1.17.2
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # DailyImage
2
2
 
3
- 日签 Or 日历,生成一张当日的图片。Just For Fun!👏
3
+ 日签 Or 日历,生成一张指定日期的图片,可作为日历。Just For Fun!👏
4
+
5
+ [PHP实现版本](https://github.com/dolphin836/make-calendar-image)
6
+ [Python版本实现](https://github.com/wnma3mz/Tools/tree/master/daily_image)
7
+ [Android桌面小部件](https://github.com/fairytale110/DailyImageWidget)
4
8
 
5
9
  ## 使用
6
10
 
@@ -28,22 +32,22 @@ gem 'daily_image'
28
32
 
29
33
  # 初始项目配置
30
34
  DailyImage.configure do |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' # 文字默认字体
35
+ config.bg_color = [255, 255, 255] # 背景颜色
36
+ config.frame_color = [151, 158, 160] # 边框颜色
37
+ config.text_color = [100, 145, 170] # 文字颜色
38
+ config.date_color = [100, 145, 170] # 中间日期颜色
39
+ config.unused_color = [200, 205, 215] # 进度条未使用颜色
40
+ config.used_color = [100, 145, 170] # 进度条已使用颜色
41
+ config.out_frame_offset = 15 # 外层边框偏移量
42
+ config.in_frame_offset = 50 # 下半部分内层边框偏移量
43
+ config.font = 'Hiragino Sans GB' # 文字默认字体
40
44
  end
41
45
 
42
46
  # 调用方法
43
- DailyImage.draw_image(output_path) # 默认图片存放地址,包所在的目录
47
+ DailyImage.draw_image(output_path = nil, date = Date.today) # 默认图片存放地址,包所在的目录; 默认生成为当日
44
48
 
45
49
  # 例子
46
- DailyImage.draw_image('./')
50
+ DailyImage.draw_image('./', '2018-09-30')
47
51
  ```
48
52
 
49
53
  ### 命令行
@@ -58,7 +62,7 @@ Specific options:
58
62
  -b, --bg_color BG_COLOR the image's background color
59
63
  -r, --frame_color FRAME_COLOR the image's frame color
60
64
  -t, --text_color TEXT_COLOR the image's text color
61
- -d, --date_color DATE_COLOR the middle date's text color
65
+ -c, --date_color DATE_COLOR the middle date's text color
62
66
  -n, --unused_color UNUSED_COLOR unused color of the progress bar
63
67
  -u, --used_color USED_COLOR used color of the progress bar
64
68
  -o OUT_FRAME_OFFSET, the outside frame offset
@@ -66,6 +70,7 @@ Specific options:
66
70
  -i, --in_offset IN_FRAME_OFFSET the inside frame offset
67
71
  -f, --font FONT the text font
68
72
  -s, --output OUTPUT the output path, save the new image
73
+ -d, --date Specific date the date you want to generate
69
74
 
70
75
  Common options:
71
76
  -h, --help Show the help message
@@ -75,7 +80,7 @@ Common options:
75
80
 
76
81
  ## 示例
77
82
 
78
- ![](./tmp/daily_2018-09-17.jpg)
83
+ ![](./tmp/daily_2018-10-06.jpeg)
79
84
 
80
85
  ## 感谢🙏
81
86
 
@@ -85,6 +90,10 @@ Common options:
85
90
 
86
91
  2. 诗词来自于 [一言·古诗词 API](https://github.com/xenv/gushici)
87
92
 
93
+ ## 待完成
94
+
95
+ - [ ] 使用机器学习生成古诗词,替代一言·古诗词API
96
+
88
97
  ## 如何贡献
89
98
 
90
99
  1. Fork it
@@ -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("-d", "--date_color DATE_COLOR", "the middle date's text color") do |date_color|
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)
@@ -29,7 +29,9 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
31
 
32
+ spec.add_dependency "ruby-vips", "~> 2.0.17"
33
+
32
34
  spec.add_development_dependency "bundler", "~> 1.16"
33
- spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rake", "~> 12.3", ">= 12.3.3"
34
36
  spec.add_development_dependency "minitest", "~> 5.0"
35
37
  end
@@ -1,6 +1,7 @@
1
1
  require "date"
2
2
  require "vips"
3
3
  require "daily_image/version"
4
+ require "daily_image/lunar_solar_converter"
4
5
  require "daily_image/poem"
5
6
  require "daily_image/image"
6
7
  require "daily_image/config"
@@ -17,11 +18,13 @@ module DailyImage
17
18
  DailyImage::Config.instance.configuration
18
19
  end
19
20
 
20
- def draw_image(output_path = nil)
21
+ def draw_image(output_path = nil, date = Date.today)
21
22
  output_path ||= Dir.pwd
22
- output_file = File.join(output_path, "daily_#{Date.today}.jpeg")
23
+ date = Date.parse(date.to_s) rescue Date.today
23
24
 
24
- image = DailyImage::Image.new.draw_image
25
+ output_file = File.join(output_path, "daily_#{date}.jpeg")
26
+
27
+ image = DailyImage::Image.new(date: date).draw_image
25
28
 
26
29
  image.write_to_file(output_file, Q: 100)
27
30
  end
@@ -34,7 +34,7 @@ module DailyImage
34
34
  def configuration
35
35
  @config ||= {}.tap do |config|
36
36
  config[:bg_color] = bg_color || [255, 255, 255]
37
- config[:frame_color] = frame_color || [151, 158, 160]
37
+ config[:frame_color] = frame_color || [100, 145, 170]
38
38
  config[:text_color] = text_color || [100, 145, 170]
39
39
  config[:date_color] = date_color || [100, 145, 170]
40
40
  config[:unused_color] = unused_color || [200, 205, 215]
@@ -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
@@ -27,6 +28,7 @@ module DailyImage
27
28
  image = draw_day(image)
28
29
  image = draw_date(image)
29
30
  image = draw_week(image)
31
+ image = draw_lunar_txt(image)
30
32
  image = draw_progress_txt(image)
31
33
 
32
34
  draw_progress(image)
@@ -60,7 +62,7 @@ module DailyImage
60
62
 
61
63
  # 画出中间日期
62
64
  def draw_day(image)
63
- day = Date.today.day.to_s
65
+ day = @date.day.to_s
64
66
 
65
67
  # 生成字体图片
66
68
  text = generate_text_image(day, dpi: 1000, text_color: config[:date_color])
@@ -74,7 +76,7 @@ module DailyImage
74
76
 
75
77
  # 画出左上角日期
76
78
  def draw_date(image)
77
- date = Date.today.to_s
79
+ date = @date.strftime("%Y.%m.%d")
78
80
  text = generate_text_image(date, dpi: 150)
79
81
 
80
82
  # 计算放置位置
@@ -86,21 +88,34 @@ module DailyImage
86
88
 
87
89
  # 画出右上角信息
88
90
  def draw_week(image)
89
- week_arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
90
- week = week_arr[Date.today.cwday]
91
+ week_arr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
92
+ week = week_arr[@date.cwday - 1]
91
93
 
92
94
  text = generate_text_image(week, dpi: 140)
93
95
 
94
96
  # 计算放置位置
95
- x = (image.width * 0.75).to_i
97
+ x = (image.width * 0.78).to_i
96
98
  y = (image.height * 0.09).to_i
97
99
 
98
100
  image.draw_image text, x, y, mode: :set
99
101
  end
100
102
 
103
+ # 画出农历信息
104
+ def draw_lunar_txt(image)
105
+ text = DailyImage::LunarSolarConverter.date_to_lunar(@date)
106
+
107
+ # 获取文字图片
108
+ text_image = generate_text_image(text)
109
+
110
+ x = (@width - text_image.width) / 2
111
+ y = @height * 0.4
112
+
113
+ image.draw_image text_image, x, y, mode: :set
114
+ end
115
+
101
116
  # 画出进度描述信息
102
117
  def draw_progress_txt(image)
103
- day = Date.today.yday
118
+ day = @date.yday
104
119
  percent = (percent_of_year * 100).round(2)
105
120
  text = "第 #{day} 天,进度已消耗 #{percent}%"
106
121
 
@@ -108,7 +123,7 @@ module DailyImage
108
123
  text_image = generate_text_image(text)
109
124
 
110
125
  x = (@width - text_image.width) / 2
111
- y = @height * 0.44
126
+ y = @height * 0.45
112
127
 
113
128
  image.draw_image text_image, x, y, mode: :set
114
129
  end
@@ -182,8 +197,8 @@ module DailyImage
182
197
 
183
198
  # 计算当天时间在一年的百分比
184
199
  def percent_of_year
185
- days = Date.new(Date.today.year, 12, 31).yday
186
- current_days = Date.today.yday
200
+ days = Date.new(@date.year, 12, 31).yday
201
+ current_days = @date.yday
187
202
 
188
203
  (current_days.to_f / days).round(4)
189
204
  end
@@ -0,0 +1,208 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module DailyImage
4
+ class Lunar
5
+ attr_accessor :lunar_day, :lunar_month, :lunar_year, :is_leap
6
+
7
+ def initialize(y = 0, m = 0, d = 0, leap = false)
8
+ @lunar_year = y
9
+ @lunar_month = m
10
+ @lunar_day = d
11
+ @is_leap = leap
12
+ end
13
+ end
14
+
15
+ class Solar
16
+ attr_accessor :solar_day, :solar_month, :solar_year
17
+
18
+ def initialize(y = 0, m = 0, d = 0)
19
+ @solar_year = y
20
+ @solar_month = m
21
+ @solar_day = d
22
+ end
23
+ end
24
+
25
+ class LunarSolarConverter
26
+ LUNAR_MONTH_DAYS = [
27
+ 1887, 0x1694, 0x16aa, 0x4ad5, 0xab6, 0xc4b7, 0x4ae, 0xa56, 0xb52a, 0x1d2a, 0xd54, 0x75aa, 0x156a, 0x1096d,
28
+ 0x95c, 0x14ae, 0xaa4d, 0x1a4c, 0x1b2a, 0x8d55, 0xad4, 0x135a, 0x495d, 0x95c, 0xd49b, 0x149a, 0x1a4a, 0xbaa5,
29
+ 0x16a8, 0x1ad4, 0x52da, 0x12b6, 0xe937, 0x92e, 0x1496, 0xb64b, 0xd4a, 0xda8, 0x95b5, 0x56c, 0x12ae, 0x492f,
30
+ 0x92e, 0xcc96, 0x1a94, 0x1d4a, 0xada9, 0xb5a, 0x56c, 0x726e, 0x125c, 0xf92d, 0x192a, 0x1a94, 0xdb4a, 0x16aa,
31
+ 0xad4, 0x955b, 0x4ba, 0x125a, 0x592b, 0x152a, 0xf695, 0xd94, 0x16aa, 0xaab5, 0x9b4, 0x14b6, 0x6a57, 0xa56,
32
+ 0x1152a, 0x1d2a, 0xd54, 0xd5aa, 0x156a, 0x96c, 0x94ae, 0x14ae, 0xa4c, 0x7d26, 0x1b2a, 0xeb55, 0xad4, 0x12da,
33
+ 0xa95d, 0x95a, 0x149a, 0x9a4d, 0x1a4a, 0x11aa5, 0x16a8, 0x16d4, 0xd2da, 0x12b6, 0x936, 0x9497, 0x1496, 0x1564b,
34
+ 0xd4a, 0xda8, 0xd5b4, 0x156c, 0x12ae, 0xa92f, 0x92e, 0xc96, 0x6d4a, 0x1d4a, 0x10d65, 0xb58, 0x156c, 0xb26d,
35
+ 0x125c, 0x192c, 0x9a95, 0x1a94, 0x1b4a, 0x4b55, 0xad4, 0xf55b, 0x4ba, 0x125a, 0xb92b, 0x152a, 0x1694, 0x96aa,
36
+ 0x15aa, 0x12ab5, 0x974, 0x14b6, 0xca57, 0xa56, 0x1526, 0x8e95, 0xd54, 0x15aa, 0x49b5, 0x96c, 0xd4ae, 0x149c,
37
+ 0x1a4c, 0xbd26, 0x1aa6, 0xb54, 0x6d6a, 0x12da, 0x1695d, 0x95a, 0x149a, 0xda4b, 0x1a4a, 0x1aa4, 0xbb54, 0x16b4,
38
+ 0xada, 0x495b, 0x936, 0xf497, 0x1496, 0x154a, 0xb6a5, 0xda4, 0x15b4, 0x6ab6, 0x126e, 0x1092f, 0x92e, 0xc96,
39
+ 0xcd4a, 0x1d4a, 0xd64, 0x956c, 0x155c, 0x125c, 0x792e, 0x192c, 0xfa95, 0x1a94, 0x1b4a, 0xab55, 0xad4, 0x14da,
40
+ 0x8a5d, 0xa5a, 0x1152b, 0x152a, 0x1694, 0xd6aa, 0x15aa, 0xab4, 0x94ba, 0x14b6, 0xa56, 0x7527, 0xd26, 0xee53,
41
+ 0xd54, 0x15aa, 0xa9b5, 0x96c, 0x14ae, 0x8a4e, 0x1a4c, 0x11d26, 0x1aa4, 0x1b54, 0xcd6a, 0xada, 0x95c, 0x949d,
42
+ 0x149a, 0x1a2a, 0x5b25, 0x1aa4, 0xfb52, 0x16b4, 0xaba, 0xa95b, 0x936, 0x1496, 0x9a4b, 0x154a, 0x136a5, 0xda4,
43
+ 0x15ac
44
+ ]
45
+
46
+ SOLAR11 = [
47
+ 1887, 0xec04c, 0xec23f, 0xec435, 0xec649, 0xec83e, 0xeca51, 0xecc46, 0xece3a, 0xed04d, 0xed242, 0xed436,
48
+ 0xed64a, 0xed83f, 0xeda53, 0xedc48, 0xede3d, 0xee050, 0xee244, 0xee439, 0xee64d, 0xee842, 0xeea36, 0xeec4a,
49
+ 0xeee3e, 0xef052, 0xef246, 0xef43a, 0xef64e, 0xef843, 0xefa37, 0xefc4b, 0xefe41, 0xf0054, 0xf0248, 0xf043c,
50
+ 0xf0650, 0xf0845, 0xf0a38, 0xf0c4d, 0xf0e42, 0xf1037, 0xf124a, 0xf143e, 0xf1651, 0xf1846, 0xf1a3a, 0xf1c4e,
51
+ 0xf1e44, 0xf2038, 0xf224b, 0xf243f, 0xf2653, 0xf2848, 0xf2a3b, 0xf2c4f, 0xf2e45, 0xf3039, 0xf324d, 0xf3442,
52
+ 0xf3636, 0xf384a, 0xf3a3d, 0xf3c51, 0xf3e46, 0xf403b, 0xf424e, 0xf4443, 0xf4638, 0xf484c, 0xf4a3f, 0xf4c52,
53
+ 0xf4e48, 0xf503c, 0xf524f, 0xf5445, 0xf5639, 0xf584d, 0xf5a42, 0xf5c35, 0xf5e49, 0xf603e, 0xf6251, 0xf6446,
54
+ 0xf663b, 0xf684f, 0xf6a43, 0xf6c37, 0xf6e4b, 0xf703f, 0xf7252, 0xf7447, 0xf763c, 0xf7850, 0xf7a45, 0xf7c39,
55
+ 0xf7e4d, 0xf8042, 0xf8254, 0xf8449, 0xf863d, 0xf8851, 0xf8a46, 0xf8c3b, 0xf8e4f, 0xf9044, 0xf9237, 0xf944a,
56
+ 0xf963f, 0xf9853, 0xf9a47, 0xf9c3c, 0xf9e50, 0xfa045, 0xfa238, 0xfa44c, 0xfa641, 0xfa836, 0xfaa49, 0xfac3d,
57
+ 0xfae52, 0xfb047, 0xfb23a, 0xfb44e, 0xfb643, 0xfb837, 0xfba4a, 0xfbc3f, 0xfbe53, 0xfc048, 0xfc23c, 0xfc450,
58
+ 0xfc645, 0xfc839, 0xfca4c, 0xfcc41, 0xfce36, 0xfd04a, 0xfd23d, 0xfd451, 0xfd646, 0xfd83a, 0xfda4d, 0xfdc43,
59
+ 0xfde37, 0xfe04b, 0xfe23f, 0xfe453, 0xfe648, 0xfe83c, 0xfea4f, 0xfec44, 0xfee38, 0xff04c, 0xff241, 0xff436,
60
+ 0xff64a, 0xff83e, 0xffa51, 0xffc46, 0xffe3a, 0x10004e, 0x100242, 0x100437, 0x10064b, 0x100841, 0x100a53,
61
+ 0x100c48, 0x100e3c, 0x10104f, 0x101244, 0x101438, 0x10164c, 0x101842, 0x101a35, 0x101c49, 0x101e3d, 0x102051,
62
+ 0x102245, 0x10243a, 0x10264e, 0x102843, 0x102a37, 0x102c4b, 0x102e3f, 0x103053, 0x103247, 0x10343b, 0x10364f,
63
+ 0x103845, 0x103a38, 0x103c4c, 0x103e42, 0x104036, 0x104249, 0x10443d, 0x104651, 0x104846, 0x104a3a, 0x104c4e,
64
+ 0x104e43, 0x105038, 0x10524a, 0x10543e, 0x105652, 0x105847, 0x105a3b, 0x105c4f, 0x105e45, 0x106039, 0x10624c,
65
+ 0x106441, 0x106635, 0x106849, 0x106a3d, 0x106c51, 0x106e47, 0x10703c, 0x10724f, 0x107444, 0x107638, 0x10784c,
66
+ 0x107a3f, 0x107c53, 0x107e48
67
+ ]
68
+
69
+ TIAN_GAN = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"]
70
+ DI_ZHI = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"]
71
+ MONTH = ["正月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "腊月"]
72
+ DAY = [
73
+ "初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十",
74
+ "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十",
75
+ "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"
76
+ ]
77
+
78
+ class << self
79
+
80
+ def date_to_lunar(date = Date.today)
81
+ converter = LunarSolarConverter.new
82
+ solar = Solar.new
83
+
84
+ solar.solar_year = date.year
85
+ solar.solar_month = date.month
86
+ solar.solar_day = date.day
87
+
88
+ lunar = converter.solar_to_lunar(solar)
89
+ lunar_text(lunar)
90
+ end
91
+
92
+ protected
93
+
94
+ def lunar_text(lunar)
95
+ tian_gan = TIAN_GAN[(lunar.lunar_year - 4) % 10]
96
+ di_zhi = DI_ZHI[(lunar.lunar_year - 4) % 12]
97
+ month = "#{lunar.is_leap ? '闰' : ''}#{MONTH[lunar.lunar_month - 1]}"
98
+ day = "#{DAY[lunar.lunar_day - 1]}"
99
+
100
+ "#{tian_gan}#{di_zhi}年 #{month}#{day}"
101
+ end
102
+
103
+ end
104
+
105
+ def lunar_to_solar(lunar)
106
+ offset = 0
107
+ days = LUNAR_MONTH_DAYS[lunar.lunar_year - LUNAR_MONTH_DAYS.first]
108
+ leap = get_bit_int(days, 4, 13)
109
+ loopend = leap
110
+
111
+ unless lunar.is_leap
112
+ loopend = if lunar.lunar_month <= leap || leap == 0
113
+ lunar.lunar_month - 1
114
+ else
115
+ lunar.lunar_month
116
+ end
117
+ end
118
+
119
+ (0..loopend-1).each do |i|
120
+ tmp_offset = get_bit_int(days, 1, 12 - i) == 1 ? 30 : 29
121
+
122
+ offset += tmp_offset
123
+ end
124
+
125
+ offset += lunar.lunar_day
126
+ solar11 = SOLAR11[lunar.lunar_year - SOLAR11.first]
127
+
128
+ y = get_bit_int(solar11, 12, 9)
129
+ m = get_bit_int(solar11, 4, 5)
130
+ d = get_bit_int(solar11, 5, 0)
131
+
132
+ solar_from_int(solar_to_int(y, m, d) + offset - 1)
133
+ end
134
+
135
+ def solar_to_lunar(solar)
136
+ lunar = Lunar.new(0, 0, 0, false)
137
+ index = solar.solar_year - SOLAR11.first
138
+ data = (solar.solar_year << 9) | (solar.solar_month << 5) | solar.solar_day
139
+
140
+ index -= 1 if SOLAR11[index] > data
141
+ solar11 = SOLAR11[index]
142
+
143
+ y = get_bit_int(solar11, 12, 9)
144
+ m = get_bit_int(solar11, 4, 5)
145
+ d = get_bit_int(solar11, 5, 0)
146
+ offset = solar_to_int(solar.solar_year, solar.solar_month, solar.solar_day) - solar_to_int(y, m, d)
147
+
148
+ days = LUNAR_MONTH_DAYS[index]
149
+ leap = get_bit_int(days, 4, 13)
150
+
151
+ lunar_year = index + SOLAR11.first
152
+ lunar_month = 1
153
+ offset += 1
154
+
155
+ (0..12).each do |i|
156
+ dm = get_bit_int(days, 1, 12 - i) == 1 ? 30 : 29
157
+ break if dm >= offset
158
+
159
+ lunar_month += 1
160
+ offset -= dm
161
+ end
162
+
163
+ lunar.lunar_year = lunar_year
164
+ lunar.lunar_month = lunar_month
165
+ lunar.lunar_day = offset.to_i
166
+ lunar.is_leap = false
167
+
168
+ if leap != 0 && lunar_month > leap
169
+ lunar.lunar_month = lunar_month - 1
170
+
171
+ lunar.is_leap = true if lunar_month == leap + 1
172
+ end
173
+
174
+ lunar
175
+ end
176
+
177
+ private
178
+
179
+ def get_bit_int(data, length, shift)
180
+ (data & (((1 << length) - 1) << shift)) >> shift
181
+ end
182
+
183
+ def solar_to_int(y, m, d)
184
+ m = (m + 9) % 12
185
+ y -= m / 10
186
+
187
+ 365 * y + y / 4 - y / 100 + y / 400 + (m * 306 + 5) / 10 + (d - 1)
188
+ end
189
+
190
+ def solar_from_int(g)
191
+ y = (10000 * g + 14780) / 3652425
192
+ ddd = g - (365 * y + y / 4 - y / 100 + y / 400)
193
+
194
+ if ddd < 0
195
+ y -= 1
196
+ ddd = g - (365 * y + y / 4 - y / 100 + y / 400)
197
+ end
198
+
199
+ mi = (100 * ddd + 52) / 3060
200
+ mm = (mi + 2) % 12 + 1
201
+ y += (mi + 2) / 12
202
+ dd = ddd - (mi * 306 + 5) / 10 + 1
203
+
204
+ Solar.new(y, mm, dd)
205
+ end
206
+
207
+ end
208
+ end
@@ -15,7 +15,7 @@ require "json"
15
15
  module DailyImage
16
16
  class Poem
17
17
 
18
- API_URL = "https://api.gushi.ci/all.json"
18
+ API_URL = "https://v1.jinrishici.com/all.json"
19
19
 
20
20
  def txt
21
21
  get(API_URL)
@@ -1,3 +1,3 @@
1
1
  module DailyImage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.5"
3
3
  end
Binary file
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daily_image
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - renyijiu
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-20 00:00:00.000000000 Z
11
+ date: 2020-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-vips
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.17
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.17
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -30,14 +44,20 @@ dependencies:
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '10.0'
47
+ version: '12.3'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 12.3.3
34
51
  type: :development
35
52
  prerelease: false
36
53
  version_requirements: !ruby/object:Gem::Requirement
37
54
  requirements:
38
55
  - - "~>"
39
56
  - !ruby/object:Gem::Version
40
- version: '10.0'
57
+ version: '12.3'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 12.3.3
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: minitest
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -63,6 +83,7 @@ extensions: []
63
83
  extra_rdoc_files: []
64
84
  files:
65
85
  - ".gitignore"
86
+ - ".ruby-version"
66
87
  - ".travis.yml"
67
88
  - CODE_OF_CONDUCT.md
68
89
  - Gemfile
@@ -76,15 +97,17 @@ files:
76
97
  - lib/daily_image.rb
77
98
  - lib/daily_image/config.rb
78
99
  - lib/daily_image/image.rb
100
+ - lib/daily_image/lunar_solar_converter.rb
79
101
  - lib/daily_image/poem.rb
80
102
  - lib/daily_image/version.rb
81
103
  - tmp/daily_2018-09-14.jpg
82
104
  - tmp/daily_2018-09-17.jpg
105
+ - tmp/daily_2018-10-06.jpeg
83
106
  homepage: https://github.com/renyijiu/daily_image
84
107
  licenses: []
85
108
  metadata:
86
109
  allowed_push_host: https://rubygems.org
87
- post_install_message:
110
+ post_install_message:
88
111
  rdoc_options: []
89
112
  require_paths:
90
113
  - lib
@@ -99,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
122
  - !ruby/object:Gem::Version
100
123
  version: '0'
101
124
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.7.6
104
- signing_key:
125
+ rubygems_version: 3.0.3
126
+ signing_key:
105
127
  specification_version: 4
106
128
  summary: "A gem generate a daily image. Just For Fun \U0001F60A"
107
129
  test_files: []