nblog_duo 111.117.789 → 111.117.799

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nblog_duo.rb +63 -19
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8aacf440b1da5f2bf2010e1e6a77d25bd64bd842e5fe05fc5e1106713279956f
4
- data.tar.gz: 465893a34609ca2146eeaea1ccb6d7d2b360775ad8ee29da454aa4b390ebde15
3
+ metadata.gz: 940713ad87c1465d1d61e78b4c8a26909bedfa07c8702d8aebde43ebe3213753
4
+ data.tar.gz: aed59cefb0316a53eb68d47ac630983f87caec7b25399fe050dd6ba1fc5695f3
5
5
  SHA512:
6
- metadata.gz: 427d5445e0c14c2e83981478823477e186a0c333dac46b25ea4db0cc5bad7703042d37c4bb85cd86243fa6f32db59df1f1041dcb251bae1f7f97aba6a266dcb1
7
- data.tar.gz: 88bea7627f4c17ca3a2526c5f85daa3668b2513e7f7674d4bbfba90738813ea63afb1fcb6695dcee1c4ee583eca11596dead6636683e5be9de405e20a9ad8fd4
6
+ metadata.gz: e62cfaa81e78c58fbc336297e70c1c81f4015a52a94680e252500f651763892ccbb9a26bc438840bf704baf552a1f4f2633c5c2fc60d4ecff1e1eab9d502849d
7
+ data.tar.gz: 99fc13abe707cb4b1ebdf45c68ed009dc37910ecb4ca94325c143f4f100f641e6a7d7a54beb2cb90b7aa9eb12d0863e4e72e569f00a3fdaff4d09af41c53de11
data/lib/nblog_duo.rb CHANGED
@@ -2389,40 +2389,84 @@ class Wordpress
2389
2389
  img.write('./image/memory.png')
2390
2390
  end
2391
2391
 
2392
+ def wrap_text_to_fit(draw, text, max_width, max_height, font_path, initial_size)
2393
+ size = initial_size
2394
+ draw.font = font_path
2395
+
2396
+ loop do
2397
+ draw.pointsize = size
2398
+ words = text.chars # 글자 단위로 자름 (한국어 기준)
2399
+ lines = []
2400
+ line = ""
2401
+
2402
+ words.each do |char|
2403
+ test_line = line + char
2404
+ metrics = draw.get_type_metrics(test_line)
2405
+ if metrics.width > max_width
2406
+ lines << line
2407
+ line = char
2408
+ else
2409
+ line = test_line
2410
+ end
2411
+ end
2412
+ lines << line unless line.empty?
2413
+
2414
+ line_height = draw.get_type_metrics("가").height
2415
+ total_height = line_height * lines.size
2416
+
2417
+ # 세로 초과 안 하면 성공
2418
+ if total_height <= max_height || size <= 10
2419
+ return [lines.join("\n"), size]
2420
+ else
2421
+ size -= 2
2422
+ end
2423
+ end
2424
+ end
2425
+
2426
+
2392
2427
  def image_text(text1, text2)
2393
2428
  begin
2394
2429
  color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
2395
- font = Dir.entries('./fonts')
2396
- img = Magick::Image.read('./image/memory.png').first
2397
- text = Magick::Draw.new
2430
+ font_files = Dir.entries('./fonts').select { |f| f.downcase.end_with?('.ttf') }
2431
+ font2 = './fonts/' + font_files.sample
2398
2432
  color2 = color.sample
2399
- font2 = './fonts/'+font.sample
2400
- message = text1.to_s+"\n"+text2.to_s
2433
+
2434
+ img = Magick::Image.read('./image/memory.png').first
2435
+ draw = Magick::Draw.new
2436
+
2437
+ raw_message = "#{text1}\n#{text2}".strip
2438
+ max_width = img.columns * 0.85
2439
+ max_height = img.rows * 0.6
2440
+
2401
2441
  begin
2402
2442
  size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
2403
2443
  rescue
2404
2444
  size = 30
2405
2445
  end
2446
+
2447
+ wrapped_message, adjusted_size = wrap_text_to_fit(draw, raw_message, max_width, max_height, font2, size)
2448
+
2406
2449
  if @data['이미지설정']['글자그림자'].checked?
2407
- img.annotate(text, 0,0, +3,+3, message) do
2408
- text.gravity = Magick::CenterGravity
2409
- text.pointsize = size
2410
- text.fill = '#000000'
2411
- text.font = font2
2450
+ img.annotate(draw, 0, 0, 2, 2, wrapped_message) do
2451
+ draw.gravity = Magick::CenterGravity
2452
+ draw.pointsize = adjusted_size
2453
+ draw.fill = '#000000'
2454
+ draw.font = font2
2412
2455
  end
2413
2456
  end
2414
-
2415
- img.annotate(text, 0,0,0,0, message) do
2416
- text.gravity = Magick::CenterGravity
2417
- text.pointsize = size
2457
+
2458
+ draw2 = Magick::Draw.new
2459
+ img.annotate(draw2, 0, 0, 0, 0, wrapped_message) do
2460
+ draw2.gravity = Magick::CenterGravity
2461
+ draw2.pointsize = adjusted_size
2462
+ draw2.fill = color2
2463
+ draw2.font = font2
2418
2464
  if @data['이미지설정']['글자테두리'].checked?
2419
- text.stroke_width = 2
2420
- text.stroke = '#000000'
2465
+ draw2.stroke_width = 2
2466
+ draw2.stroke = '#000000'
2421
2467
  end
2422
- text.fill = color2
2423
- text.font = font2
2424
2468
  end
2425
-
2469
+
2426
2470
  img.write('./image/memory.png')
2427
2471
  rescue
2428
2472
  puts '이미지 폰트 불러오기 오류 재시도...'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nblog_duo
3
3
  version: !ruby/object:Gem::Version
4
- version: 111.117.789
4
+ version: 111.117.799
5
5
  platform: ruby
6
6
  authors:
7
7
  - zon