nblog_zon 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_zon.rb +83 -39
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8fa0de35ccb453ed183232c89506cc94d1e862495dbb7398100ac52848cfe64
4
- data.tar.gz: 8dbca3b1ce745f549c442dfb0b3204c7ced2dcadca999ed05bbe23ff746c009f
3
+ metadata.gz: f01bbab47604da93c7a1b481dcba8015f4a28b6c9d004674a15c7942a649a462
4
+ data.tar.gz: 4e5563adc0adb337b30b332863ddc1d26e70294ebf4e70186282c643f1f0c927
5
5
  SHA512:
6
- metadata.gz: 37d160408f39c74f0598e6d1eab6f01373a2f69a2f851c60dd382cb3d7ac0afe8fccdb2a724c29401429a4d94413d8b7af1401fdc8697400cb24a44aa79018cc
7
- data.tar.gz: 5699d00b22583c92f3cc9333038315c33aa659193860dad395bef83e592fb71228ad8d6e1f2e4812b964ed6445c79f0fa0a28403b6605d16f84058080cf987c4
6
+ metadata.gz: adfe81061d9bf7fec6c9846ad22f6f60ef153b8d53e5f08b1a5e192aae218bfe160c09867ce7eef3b9797eecff6f2204b4f46cd81aa43954dcdfe13e8e8a159b
7
+ data.tar.gz: bce9840707738019dc6748d64ea257f3228dae0c82a1a3f32d68c1eeeddbde567654fed972d734cd0297c6da9dec9707f7efdeefeda71a1599bd079c5e80cece
data/lib/nblog_zon.rb CHANGED
@@ -2319,40 +2319,84 @@ class Wordpress
2319
2319
  img.write('./image/memory.png')
2320
2320
  end
2321
2321
 
2322
+ def wrap_text_to_fit(draw, text, max_width, max_height, font_path, initial_size)
2323
+ size = initial_size
2324
+ draw.font = font_path
2325
+
2326
+ loop do
2327
+ draw.pointsize = size
2328
+ words = text.chars # 글자 단위로 자름 (한국어 기준)
2329
+ lines = []
2330
+ line = ""
2331
+
2332
+ words.each do |char|
2333
+ test_line = line + char
2334
+ metrics = draw.get_type_metrics(test_line)
2335
+ if metrics.width > max_width
2336
+ lines << line
2337
+ line = char
2338
+ else
2339
+ line = test_line
2340
+ end
2341
+ end
2342
+ lines << line unless line.empty?
2343
+
2344
+ line_height = draw.get_type_metrics("가").height
2345
+ total_height = line_height * lines.size
2346
+
2347
+ # 세로 초과 안 하면 성공
2348
+ if total_height <= max_height || size <= 10
2349
+ return [lines.join("\n"), size]
2350
+ else
2351
+ size -= 2
2352
+ end
2353
+ end
2354
+ end
2355
+
2356
+
2322
2357
  def image_text(text1, text2)
2323
2358
  begin
2324
2359
  color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
2325
- font = Dir.entries('./fonts')
2326
- img = Magick::Image.read('./image/memory.png').first
2327
- text = Magick::Draw.new
2360
+ font_files = Dir.entries('./fonts').select { |f| f.downcase.end_with?('.ttf') }
2361
+ font2 = './fonts/' + font_files.sample
2328
2362
  color2 = color.sample
2329
- font2 = './fonts/'+font.sample
2330
- message = text1.to_s+"\n"+text2.to_s
2363
+
2364
+ img = Magick::Image.read('./image/memory.png').first
2365
+ draw = Magick::Draw.new
2366
+
2367
+ raw_message = "#{text1}\n#{text2}".strip
2368
+ max_width = img.columns * 0.85
2369
+ max_height = img.rows * 0.6
2370
+
2331
2371
  begin
2332
2372
  size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
2333
2373
  rescue
2334
2374
  size = 30
2335
2375
  end
2376
+
2377
+ wrapped_message, adjusted_size = wrap_text_to_fit(draw, raw_message, max_width, max_height, font2, size)
2378
+
2336
2379
  if @data['이미지설정']['글자그림자'].checked?
2337
- img.annotate(text, 0,0, +3,+3, message) do
2338
- text.gravity = Magick::CenterGravity
2339
- text.pointsize = size
2340
- text.fill = '#000000'
2341
- text.font = font2
2380
+ img.annotate(draw, 0, 0, 2, 2, wrapped_message) do
2381
+ draw.gravity = Magick::CenterGravity
2382
+ draw.pointsize = adjusted_size
2383
+ draw.fill = '#000000'
2384
+ draw.font = font2
2342
2385
  end
2343
2386
  end
2344
-
2345
- img.annotate(text, 0,0,0,0, message) do
2346
- text.gravity = Magick::CenterGravity
2347
- text.pointsize = size
2387
+
2388
+ draw2 = Magick::Draw.new
2389
+ img.annotate(draw2, 0, 0, 0, 0, wrapped_message) do
2390
+ draw2.gravity = Magick::CenterGravity
2391
+ draw2.pointsize = adjusted_size
2392
+ draw2.fill = color2
2393
+ draw2.font = font2
2348
2394
  if @data['이미지설정']['글자테두리'].checked?
2349
- text.stroke_width = 2
2350
- text.stroke = '#000000'
2395
+ draw2.stroke_width = 2
2396
+ draw2.stroke = '#000000'
2351
2397
  end
2352
- text.fill = color2
2353
- text.font = font2
2354
2398
  end
2355
-
2399
+
2356
2400
  img.write('./image/memory.png')
2357
2401
  rescue
2358
2402
  puts '이미지 폰트 불러오기 오류 재시도...'
@@ -2417,33 +2461,33 @@ class Wordpress
2417
2461
 
2418
2462
  if @data['이미지설정']['글자삽입1'].checked?
2419
2463
  if @data['이미지설정']['이미지글자1'].length == 0
2420
- image_text_path1 = ''
2464
+ image_text_path1 = ''
2421
2465
  else
2422
- if @data['이미지설정']['글자랜덤'].checked?
2423
- image_text_path1 = @data['이미지설정']['이미지글자1'].sample
2424
- else
2425
- image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
2426
- @image_text_soon1 += 1
2427
- if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
2428
- @image_text_soon1 = 0
2429
- end
2430
- end
2466
+ if @data['이미지설정']['글자랜덤'].checked?
2467
+ image_text_path1 = @data['이미지설정']['이미지글자1'].sample
2468
+ else
2469
+ image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
2470
+ @image_text_soon1 += 1
2471
+ if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
2472
+ @image_text_soon1 = 0
2473
+ end
2474
+ end
2431
2475
  end
2432
2476
  end
2433
2477
 
2434
2478
  if @data['이미지설정']['글자삽입2'].checked?
2435
2479
  if @data['이미지설정']['이미지글자2'].length == 0
2436
- image_text_path2 = ''
2480
+ image_text_path2 = ''
2437
2481
  else
2438
- if @data['이미지설정']['글자랜덤'].checked?
2439
- image_text_path2 = @data['이미지설정']['이미지글자2'].sample
2440
- else
2441
- image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
2442
- @image_text_soon2 += 1
2443
- if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
2444
- @image_text_soon2 = 0
2445
- end
2446
- end
2482
+ if @data['이미지설정']['글자랜덤'].checked?
2483
+ image_text_path2 = @data['이미지설정']['이미지글자2'].sample
2484
+ else
2485
+ image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
2486
+ @image_text_soon2 += 1
2487
+ if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
2488
+ @image_text_soon2 = 0
2489
+ end
2490
+ end
2447
2491
  end
2448
2492
  end
2449
2493
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nblog_zon
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